Ios custom tableViewcell, UITableViewCell

Source: Internet
Author: User

Ios custom tableViewcell, UITableViewCell

 

 

 

// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.

View the attachment for the demo Effect

# Import

# Import "Houses. h"

# Define kRowWidth [UIScreen mainScreen]. bounds. size. width

# Define kRowHeight 90

@ Interface HouseTableViewCell: UITableViewCell

 

-(Void) setHouses :( Houses *) houses;

 

@ End

 

# Import "HouseTableViewCell. h"

 

@ Interface HouseTableViewCell ()

{

UIImageView * _ imageView;

UILabel * _ titleLabel;

UILabel * _ subLabel;

UILabel * _ skimNums;

}

@ End

 

 

 

@ Implementation HouseTableViewCell

 

-(Instancetype) initWithStyle :( UITableViewCellStyle) style reuseIdentifier :( NSString *) reuseIdentifier {

Self = [super initWithStyle: style reuseIdentifier: reuseIdentifier];

If (self ){

[Self _ addSubviews];

}

Return self;

}

 

 

# Pragma mark-_ addSubviews

-(Void) _ addSubviews {

 

// 1. Add image_imageview

_ ImageView = [[UIImageView alloc] initWithFrame: CGRectMake (5, 5, kRowHeight-10, kRowHeight-10)];

 

[Self addSubview: _ imageView];

 

// 2. Add the title _ titleLabel

_ TitleLabel = [[UILabel alloc] initWithFrame: CGRectMake (_ imageView. frame. origin. x * 2 + _ imageView. frame. size. width, _ imageView. frame. origin. y, kRowWidth-_ imageView. frame. origin. x * 2-_ imageView. frame. size. width, 45)];

_ TitleLabel. font = [UIFont boldSystemFontOfSize: 18];

_ TitleLabel. textColor = [UIColor grayColor];

[Self addSubview: _ titleLabel];

 

// 3. add subtitle _ subLabel

_ SubLabel = [[UILabel alloc] initWithFrame: CGRectMake (_ imageView. frame. origin. x * 2 + _ imageView. frame. size. width, kRowHeight-45, kRowWidth-_ imageView. frame. origin. x * 2-_ imageView. frame. size. width, 35)];

 

[Self addSubview: _ subLabel];

_ SubLabel. font = [UIFont boldSystemFontOfSize: 12];

_ SubLabel. textColor = [UIColor grayColor];

_ SubLabel. numberOfLines = 0;

// _ SubLabel. adjustsFontSizeToFitWidth = YES;

 

// 4. Add the page views _ skimNums

_ SkimNums = [[UILabel alloc] initWithFrame: CGRectMake (kRowWidth-60-10, kRowHeight-20, 60, 25)];

_ SkimNums. adjustsFontSizeToFitWidth = YES;

[Self addSubview: _ skimNums];

 

 

 

}

 

# Pragma setHouses :( Houses *) houses

-(Void) setHouses :( Houses *) houses {// creates a class of houses to store data

NSString * imgPath = houses. imgPath;

UIImage * image = [UIImage imageNamed: imgPath];

_ ImageView. image = image;

_ TitleLabel. text = houses. titleLabel;

_ SubLabel. text = houses. subLabel;

_ SkimNums. text = [NSString stringWithFormat: @ "page views: % li", houses. skimNums];

}

 

-(Void) awakeFromNib {

// Initialization code

}

 

-(Void) setSelected :( BOOL) selected animated :( BOOL) animated {

[Super setSelected: selected animated: animated];

 

// Configure the view for the selected state

}

 

@ End


// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.


// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.


// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.


// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.


// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.


// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.


// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.


// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.


// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.


// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.


// Custom tableViewcell. When the system's built-in tableView style cannot meet our needs, you can use code to customize the cell.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.