为了账号安全,请及时绑定邮箱和手机立即绑定

有没有什么办法,让UITextView可以预留边距的?用一个UITextView解决问题?

有没有什么办法,让UITextView可以预留边距的?用一个UITextView解决问题?

iOS
慕丝7291255 2023-04-15 13:09:10
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);

再看效果


查看完整回答
反对 回复 2023-04-18
?
慕尼黑5688855

TA贡献1848条经验 获得超2个赞

ios7下新增了一个属性textContainerInset,
self.textView.textContainerInset = UIEdgeInsetsMake(10, 10, 0, 10);//设置页边距
上边距10,左右边距各10,底边距0

查看完整回答
反对 回复 2023-04-18
  • 2 回答
  • 0 关注
  • 88 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信