In most of the iOS application UITableView plays huge role. UITableViewCell is the default cell for UITableView and it has only limited layout object attributes say titleLabel, detailTextlabel, imageView which are not sufficient to show out required layouts.
So in order to overcome such inconvenience we can create our own custom cell according to our requirement. Let's follow the below steps to create custom tableview cell.
Before going to coding and layout, let's define our requirement and layout as shown below image
2) Select single view application and click next
Select the name label and specify the related constraints as shown in the image
Select the date time label and specify the related constraints as shown in the image
Select the quote label and specify the related constraints as shown in the image
Let's go into the coding part
Connect all the tableviewcell objects to it's owned class QuotesTableViewCell.
Write the following code in the ViewController
Finally, we are done with the coding part also so let's try running the program.
Download complete code.
So in order to overcome such inconvenience we can create our own custom cell according to our requirement. Let's follow the below steps to create custom tableview cell.
Before going to coding and layout, let's define our requirement and layout as shown below image
The image shows the list of quotes form Big bang theory with different characters.
1) Let's create new xcode application as CustomTableView
2) Select single view application and click next
3) After creating new project, try to create new Cocoa Touch Class for custom tableview cell.
4) Name the class as QuoteTableViewCell with subclass of UITableViewCell
5) Let's open storyboard file to design our UI, select the ViewController and add navigation controller to it.
5) Put UI element on view, drag and drop UITableView and give autolayout constrains to it.
6) Drop UITableViewCell on tableview and design ui components according to our requirement. After done with design do specify the custom class name
7) Connect Tableview delegate and datasource to Viewcontroller
8) Set the autolayout constraints for each subview of QuoteTableViewCell's ContentView as shown below.
Select the imageview and specify the related constraints as shown in the image
Select the name label and specify the related constraints as shown in the image
Select the date time label and specify the related constraints as shown in the image
Select the quote label and specify the related constraints as shown in the image
Let's go into the coding part
Connect all the tableviewcell objects to it's owned class QuotesTableViewCell.
Write the following code in the ViewController
Finally, we are done with the coding part also so let's try running the program.
Download complete code.














0 Comments