[ad_1]
Create dynamic top UITableViewCell in Swift
On this tutorial, we’ll learn to create dynamic top UITableViewCell in Swift. To realize dynamic top we’ll create multi line UILabel in UITableView utilizing swift language.
We’ll use the brand new UITableViewAutomaticDimension property. UITableViewAutomaticDimension property is a useful factor for iOS builders because it units the cell top robotically. The one situation is that you simply arrange your cell constraints appropriately. So allow us to study, how we are able to create dynamic top UITableViewCell in UITableView utilizing swift.
Steps to create the multi line UILable in UITableViewCell of the UITableView
1: Create a single view utility and title it “Multi-Line-UILable”. After creating the venture you will note following information contained by the venture (i’m mentioning solely 3 information right here)
- AppDelegate.swift
- ViewController.swift
- Most important.Storyboard
2: Open ViewController.swift and create an IBOutLet for UITableView.
3: Create a brand new file which is a base class of UITableViewCell class and title it “MultilineLabelCell”.
4: Open MultilineLabelCell.xib and comply with the steps as proven within the beneath picture sequence. Right here constraints will play essential function in figuring out UITableViewCell top, as a result of autolayout at all times contemplate the constraint throughout rendering of the content material. In our case the cell will at all times have 11.5 pixel area from backside of the cell. Although, you’ll be able to change fixed worth of backside constraint to see the totally different eventualities.
5: Open MultilineLabelCell.swift and create IBOutlet for the UILabel.
6: Open MultilineLabelCell.xib and join IBOutlet lblTitle to UILabel.
7: Open ViewController.swift and add beneath code.
Within the above code, first we created IBOutlet for UITableView and named it as tblList. Secondly, we set delegate and datasource for our tblList UITbaleView. Subsequent we have to inform the default estimated row top in order that it improved efficiency as defined by APPLE. Lastly telling our ViewController.swift class that we’re going to implement delegate and datasource for UITableView.
As we’re utilizing customized class so we have to register customized cell xib title in viewdidload. By now you’re seeing error in your xcode, that’s as a result of we haven’t but carried out the delagets and datasource for uITableView.
Step 8: Under is the whole code that can produce dynamic cell top for UITableView row, as per the content material displayed by UILabel.
Run your code and you will note, cell of dynamic top based mostly on content material size.
[ad_2]






