HomeiOS DevelopmentCreate dynamic peak UITableViewCell – iOSTutorialJunction

Create dynamic peak UITableViewCell – iOSTutorialJunction


Create dynamic peak UITableViewCell – iOSTutorialJunction

Create dynamic peak UITableViewCell in Swift

On this tutorial, we’ll learn to create dynamic peak UITableViewCell in Swift. To attain dynamic peak we’ll create multi line UILabel in UITableView utilizing swift language.

                                     We are going to use the brand new UITableViewAutomaticDimension property. UITableViewAutomaticDimension property is a helpful factor for iOS builders because it units the cell peak robotically. The one situation is that you just arrange your cell constraints appropriately. So allow us to be taught, how we will create dynamic peak UITableViewCell in UITableView utilizing swift.

Steps to create the multi line UILable in UITableViewCell of the UITableView

1: Create a single view utility and identify it “Multi-Line-UILable”. After creating the venture you will notice following information contained by the venture (i’m mentioning solely 3 information right here)

  • AppDelegate.swift
  • ViewController.swift
  • Major.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 identify it “MultilineLabelCell”.

Creating MultilineLabel UItableViewCell class

4: Open MultilineLabelCell.xib and observe the steps as proven within the under picture sequence. Right here constraints will play vital position in figuring out  UITableViewCell peak, as a result of autolayout all the time take into account the constraint throughout rendering of the content material. In our case the cell will all the time  have 11.5 pixel area from backside of the cell. Although, you may change fixed worth of backside constraint to see the completely different situations.

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 under 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 peak 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 identify in viewdidload. By now you might be 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 may produce dynamic cell peak for UITableView row, as per the content material displayed by UILabel.

Run your code and you will notice, cell of dynamic peak based mostly on content material size.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments