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

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];

http://img3.mukewang.com/643e67ca0001de6307381288.jpg


慕丝7291255
浏览 97回答 2
2回答

宝慕林4294392

可以使用contentInset这个属性textView.contentInset = UIEdgeInsetsMake(10.0f, 10.0f, 10.0f, 10.0f);再看效果

慕尼黑5688855

ios7下新增了一个属性textContainerInset,self.textView.textContainerInset = UIEdgeInsetsMake(10, 10, 0, 10);//设置页边距上边距10,左右边距各10,底边距0
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

iOS