UITextView的對(duì)齊方式如果選擇左對(duì)齊,內(nèi)容直接頂?shù)阶筮吜?,如果選擇劇中,換行的時(shí)候就超級(jí)惡心,兩個(gè)字也會(huì)在中間。我現(xiàn)在的做法是,在UITextView背后貼了一個(gè)背景,感覺(jué)有點(diǎn)惡心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貢獻(xiàn)2021條經(jīng)驗(yàn) 獲得超8個(gè)贊
可以使用contentInset這個(gè)屬性
textView.contentInset = UIEdgeInsetsMake(10.0f, 10.0f, 10.0f, 10.0f);
再看效果

慕尼黑5688855
TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊
ios7下新增了一個(gè)屬性textContainerInset,
self.textView.textContainerInset = UIEdgeInsetsMake(10, 10, 0, 10);//設(shè)置頁(yè)邊距
上邊距10,左右邊距各10,底邊距0
- 2 回答
- 0 關(guān)注
- 173 瀏覽
添加回答
舉報(bào)
0/150
提交
取消