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];
2 回答
宝慕林4294392
TA贡献2021条经验 获得超8个赞
可以使用contentInset这个属性
textView.contentInset = UIEdgeInsetsMake(10.0f, 10.0f, 10.0f, 10.0f);
再看效果
慕尼黑5688855
TA贡献1848条经验 获得超2个赞
ios7下新增了一个属性textContainerInset,
self.textView.textContainerInset = UIEdgeInsetsMake(10, 10, 0, 10);//设置页边距
上边距10,左右边距各10,底边距0
- 2 回答
- 0 关注
- 146 浏览
添加回答
举报
0/150
提交
取消