Reputation: 1017
I have a cell which may have to display a long text. In this case it should wrap to a second line.
I have Lines set to 2 and Line Break set to Word Wrap in the attributes Inspector. The Interface Builder preview confirm that and behaves as expected/desired.
When building and running however the text is limited to one line and truncuates at the tail:
Other changes in the attribute inspector seem to have no effect aswell (text alignment for example)!
Upvotes: 6
Views: 6284
Reputation: 7025
The constraints might not have set properly for the UILabel. So, the UILabel will keep on expanding as the text increases.
Upvotes: 0
Reputation: 81
If anyone is still having the problem.. Here's the solution for swift 4 Xcode 9 iOS 11
inside the cellForRowAt tableview function you just have to add a single line of code
cell?.textLabel?.numberOfLines = 0
Upvotes: 8
Reputation: 1
If you want to have multiple lines in label so in attributes inspector set lines to 0 and implement
tableView.rowHeight = UITableViewAutomaticDimension
Upvotes: 0
Reputation: 57
For getting the lines without the dots, Do the following -
I think this will work.
Upvotes: 3
Reputation: 6992
You can implement automatic cell sizing depending on the label's text size
tableView.rowHeight = UITableViewAutomaticDimension
This will make the cells resize according to label's contents
Upvotes: 0
Reputation: 684
Swift 3
Add Two Methods in tableview.
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
Upvotes: 5