Reputation: 1621
Here I have attched images of my emulater view and xcode xib view.
This is the place I have attached string to UILabel
cell.nameLabel.text = self.dataSourceArray[indexPath.row][@"medicine"][@"name"];
In emulator only two lines shows for any kind of lengthy string.How can I fix it ?
Upvotes: 0
Views: 51
Reputation: 439
This has nothing to do with the text you set to the UILabel, but with the constraints used in that XIB.
If the cell has a static (non-adapting) value, and the other views interacting vertically with the UILabel won't shrink down, then the UILabel won't have space to grow, and won't show the text properly. By the way, the yellow lines in your XIB indicate that what you're seeing is not what the cell will look on runtime.
You can check by using the View Hierarchy Debugger if the UILabel has enough space to show the 3 lines you want. While the app is running (launched by Xcode), the bottom bar (probably above the debug area) there's a bottom called "Debug View Hierarchy"
Then you can decide if you wan't to reduce the spacing around that UILabel, or make the cell bigger so the UILabel can be as big as it wants. If it's the latter, check on UITaableViewCell autosizing tutorials, like Eugene mentioned.
Upvotes: 0
Reputation: 10045
The easiest way would be to use dynamic height table view cells. Setup the constraints on your UITableViewCell
properly - static heights for all elements, but the expandable label should have a More than or equals (>=)
height constraint. In your view controller add these lines in viewDidLoad:
method.
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 300
Take a look at this tutorial for more information.
Upvotes: 1