UITextView contentInset无法正常工作 [英] UITextView contentInset is not working
本文介绍了UITextView contentInset无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在UITextView中显示文字。我需要对文本应用一些填充。当我使用顶级位置的价值时,它正在运作。如果我将值用于其他位置则不起作用。
I'm displaying text inside UITextView. I need to apply some padding to text. When i use value for top position it's working. If i use value for other position it's not working.
txtt_bgImage = [UIImage imageNamed:@"txtt_bg_ipad.png"];
txtt_bgImageView = [[UIImageView alloc] initWithImage:txtt_bgImage];
txtt=[[UITextView alloc]initWithFrame:CGRectMake(170, 300, 400, 250)];
txtt.text=productDescription;
[txtt setFont: [UIFont fontWithName:@"verdana" size:15]];
txtt.textColor=[UIColor whiteColor];
[txtt setBackgroundColor:[UIColor clearColor]];
txtt.contentInset = UIEdgeInsetsMake(15,0,0,0);
// [txtt setTextContainerInset:UIEdgeInsetsMake(7, 7, 0, 0)];
txtt_bgImageView.frame=CGRectMake(170, 300, 400, 250);
[self.view addSubview:txtt_bgImageView];
txtt.editable=NO;
NSLog(@"text is %@",txtt.text);
object.object_screentext = txtt;
[self.view addSubview:txtt];
推荐答案
对于iOS7,使用 textContainerInset
@property(nonatomic, assign) UIEdgeInsets textContainerInset NS_AVAILABLE_IOS(7_0);
对于Bellow iOS7,使用 contentInset
并设置 UIEdgeInsetsMake
如下面的语法。
For Bellow iOS7 use contentInset
and setting UIEdgeInsetsMake
as bellow syntax.
UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) {
UIEdgeInsets insets = {top, left, bottom, right};
return insets;
}
根据您的代码,您只设置顶部插图但是如果您希望设置所有方面你必须设置内容插入如下: -
According to your code you are setting only top side inset But if you wish to set all side you have to set content inset like bellow :-
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
_TxtViewSummary.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
} else {
_TxtViewSummary.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
}
看起来像这样: -
That look like this:-
这篇关于UITextView contentInset无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文