简体   繁体   中英

Is there any way to alter line spacing/margins/padding for a UITextView inside a UIStackView?

So I have a prototype cell.

It's a horizontal stack view with several buttons, and a text view as the rightmost subview.

My problem is that the text view's text is too high up, which allows two lines to fit into the cell's height instead of just one. But I need to keep the font size at this value, so I can't increase it and achieve one-line-per-cell that way.

So I need to somehow make the line spacing/margins/etc. greater for the text view so that when there's only one line of text in it, the text will be centered in the cell. Or some approximation of that, such as perhaps setting margins around the text view itself.

Yet I can't seem to find a way to do any of this.

I tried setting constraints for the text view, but that just somehow makes the whole stack view vanish. I tried going into the Size Inspector for the text view and setting explicit layout margins, but Xcode altogether crashes from that completely, so I figure that's probably not allowed.

Can anyone knowledgeable about UITextViews please share some insight?

使用UITextField并将高度约束设置为大于等于优先级250的值。

After further research and testing, this appears to be the best way to set insets for the text in a text view:

cellField.textContainerInset = UIEdgeInsetsMake(10.0, 0.0, 10.0, 0.0)

The same thing can be set via Storyboard in the UITextView's Identity Inspector tab by adding a "textContainerInset" runtime attribute with type "Rect" and setting desired values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM