gpt4 book ai didi

iphone - 向 UITextView 添加左边距

转载 作者:技术小花猫 更新时间:2023-10-29 10:29:49 26 4
gpt4 key购买 nike

我正在尝试向 UITextView 添加左边距。

我试过设置属性 contentInset,见下文:

UITextView *textView = [[UITextView alloc] initWithFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
textView.editable = YES;
textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
textView.backgroundColor = [UIColor clearColor];
textView.opaque = NO;
textView.contentInset = UIEdgeInsetsMake(0, 15.0f, 0, 0);

虽然它会导致我不想要的 TextView 上的水平滚动,但这似乎可行。

我只想在左侧插入文本而不使 TextView 变宽。

最佳答案

请记住,对于 iOS 7,有一个名为

的特殊属性

textContainerInset The inset of the text container's layout area within the text view's content area.

@property(nonatomic, assign) UIEdgeInsets textContainerInset

This property provides text margins for text laid out in the text view.

Availability Available in iOS 7.0 and later. Declared In UITextView.h

在 iOS 6 中,contentInset 正在做这项工作。我个人遇到过这个问题。一切都结束了:

if (isIOS7()) {
textView.textContainerInset = UIEdgeInsetsMake(0, 10, 0, 10);
} else {
textView.contentInset = UIEdgeInsetsMake(0, 10, 0, 10);
}

关于iphone - 向 UITextView 添加左边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7010036/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com