自定义等高的cell(代码Autolayout)
来源:互联网 发布:sqlserver history 编辑:程序博客网 时间:2024/05/16 12:37
//// tgCell.m#import "tgCell.h"#import "tgModel.h"//define this constant if you want to use Masonry without the 'mas_' prefix#define MAS_SHORTHAND//define this constant if you want to enable auto-boxing for default syntax#define MAS_SHORTHAND_GLOBALS#import "Masonry.h"@interface tgCell()@property (weak, nonatomic) UIImageView *iconView;@property (weak, nonatomic) UILabel *titleLabel;@property (weak, nonatomic) UILabel *priceLabel;@property (weak, nonatomic) UILabel *buyCountLabel;@end@implementation tgCell// 1.在initWithStyle:reuseIdentifier:方法中添加子控件- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { CGFloat margin = 10; UIImageView *iconView = [[UIImageView alloc] init]; [self.contentView addSubview:iconView]; self.iconView = iconView; [iconView makeConstraints:^(MASConstraintMaker *make) { make.width.equalTo(100); make.left.top.offset(margin); make.bottom.offset(-margin); }]; UILabel *titleLabel = [[UILabel alloc] init]; [self.contentView addSubview:titleLabel]; self.titleLabel = titleLabel; [titleLabel makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(iconView); make.left.equalTo(iconView.right).offset(margin); make.right.offset(-margin); }]; UILabel *priceLabel = [[UILabel alloc] init]; priceLabel.textColor = [UIColor orangeColor]; [self.contentView addSubview:priceLabel]; self.priceLabel = priceLabel; [priceLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(titleLabel); make.bottom.equalTo(iconView); make.width.equalTo(70); }]; UILabel *buyCountLabel = [[UILabel alloc] init]; buyCountLabel.textAlignment = NSTextAlignmentRight; buyCountLabel.font = [UIFont systemFontOfSize:14]; buyCountLabel.textColor = [UIColor lightGrayColor]; [self.contentView addSubview:buyCountLabel]; self.buyCountLabel = buyCountLabel; [buyCountLabel makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(priceLabel); make.right.equalTo(titleLabel); make.left.equalTo(priceLabel.left).offset(margin); }]; } return self;}// 3.重写模型的set方法- (void)setModel:(tgModel *)model{ _model = model; //设置数据 self.iconView.image = [UIImage imageNamed:model.icon]; self.titleLabel.text = model.title; self.priceLabel.text = [NSString stringWithFormat:@"¥%@",model.price]; self.buyCountLabel.text = [NSString stringWithFormat:@"%@人已购买",model.buyCount];}+ (instancetype)cellWithTableView:(UITableView *)tableView{ static NSString *ID = @"cell"; tgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (cell == nil) { cell = [[tgCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID]; } return cell;}@end
0 0
- 自定义等高的cell(代码Autolayout)
- UI 一一 自定义等高cell (纯代码-Autolayout)方式
- 自定义等高的cell(纯代码)
- 自定义等高的cell
- 自定义等高的cell
- 自定义等高的cell(代码创建frame)
- 自定义等高的cell(使用stroyboard)
- 自定义等高的cell(使用XIB)
- 有关自定义等高的cell方法
- 自定义等高的cell(storyboard)
- 自定义等高的cell(xib)
- xib自定义非等高的cell
- storyboard自定义非等高的Cell
- UI 一一 自定义等高cell (纯代码-Frame)方式
- iOS 自定义等高cell
- 自定义等高cell和不等高cell的方式对比
- 使用autolayout自定义动态高度的cell
- tableView - 自定义等高cell-storyBoard方式
- HDU 1005.Number Sequence【用递归会超时】(2.5)
- eval解析JSON注意点
- Theano 逻辑回归教程 的注释
- HDU 1247 Hat’s Words
- HTML5开发移动web应用——Sencha Touch篇(8)
- 自定义等高的cell(代码Autolayout)
- Android基础之Fragment2
- NSWindow.setFrame的坑
- Scanf函数的输入问题
- Open Credit System
- 查找二叉树
- HDU 4612 Warm up(边双连通分量)
- 队列
- Exercise1_3_37