UITextView的对齐方式如果选择左对齐,内容直接顶到左边了,如果选择剧中,换行的时候就超级恶心,两个字也会在中间。
我现在的做法是,在UITextView背后贴了一个背景,感觉有点恶心
self.view.backgroundColor = [UIColor lightGrayColor];
UIView *textViewBg = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 300.0f, 170.0f)];
[self.view addSubview:textViewBg];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20.0f, 20.0f, 280.0f, 150.0f)];
textView.backgroundColor = [UIColor whiteColor];
textView.textAlignment = UITextAlignmentLeft;
textView.font = [UIFont systemFontOfSize:16.0f];
[self.view addSubview:textView];
有没有什么办法,让UITextView可以预留边距的?用一个UITextView解决问题
可以使用contentInset这个属性
textView.contentInset = UIEdgeInsetsMake(10.0f, 10.0f, 10.0f, 10.0f);
再看效果
ios7下新增了一个属性textContainerInset,
self.textView.textContainerInset = UIEdgeInsetsMake(10, 10, 0, 10);//设置页边距
上边距10,左右边距各10,底边距0
你现在的做法挺好的,我看来比改内间距要好。非要改的话对其中的scroll view设置scrollEdgeInsets
正文完