ios 自訂tableViewcell,UITableViewCell

來源:互聯網
上載者:User

ios 自訂tableViewcell,UITableViewCell

 

 

 

//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell

demo效果看附件

#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.添加圖片_imageView

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

 

[self addSubview:_imageView];

 

// 2.添加標題_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.添加副標題_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.添加瀏覽量_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{//建立一個類houses,用來存數資料

NSString * imgPath = houses.imgPath;

UIImage * image = [UIImage imageNamed:imgPath];

_imageView.image = image;

_titleLabel.text = houses.titleLabel ;

_subLabel.text = houses.subLabel;

_skimNums.text = [NSString stringWithFormat:@"瀏覽量:%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


//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell


//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell


//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell


//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell


//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell


//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell


//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell


//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell


//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell


//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell


//自訂tableViewcell,當系統內建的tableView樣式無法滿足我們的需求可通過代碼實現自訂cell



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.