The problem coming even in storyboard.
The UILabel is having following properties:
As you can see the fourth word cannot fit in the first line and hence a problem by creating bad layout. If I remove the last word the sentence fits in one line completely or say the fourth word. If adding a word after it moves both of them to next line which leaves a lot of space. It should try to fit words without breaking or hyphenation as much as possible in one line. But clearly empty space is made even when word can fit.
You can recreate this in a new project and observe the issue.
You may want to give this a try...
Subclass UITextView
, disable scrolling, editing and selecting... set the textContainerInset = UIEdgeInsets.zero
and textContainer.lineFragmentPadding = 0
to Zero.
Result:
Code (@IBDesignable
so we can see it in IB / Storyboard):
@IBDesignable
class TextViewLabel: UITextView {
override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
func commonInit() -> Void {
isScrollEnabled = false
isEditable = false
isSelectable = false
textContainerInset = UIEdgeInsets.zero
textContainer.lineFragmentPadding = 0
}
}