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.