前言: 在这篇文章中你可以学到什么? Masonry布局, Block 以及动画, 俗称的懒加载. (想了解的看一看). 0.-
tableViewCell
布局篇–为方便大家查看, 我会尽量贴出全部代码
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/***/ typedef void(^btnPulsBlock)(NSInteger count, BOOL animated); @interface XTFoodCell : UITableViewCell @property (nonatomic, strong) UIImageView *foodImage; // cyan @property (nonatomic, strong) UILabel *nameLabel; // orange @property (nonatomic, strong) UILabel *priceLabel; // gray @property (nonatomic, strong) UIButton *btnMinus; // black @property (nonatomic, strong) UIButton *btnPlus; // black @property (nonatomic, strong) UILabel *orderCount; // red @property (nonatomic, copy) btnPulsBlock block; // block @property (nonatomic, strong) UIImageView *animateView; // 购物车图标 @property (nonatomic, assign) NSInteger numCount; // 计数器 @end |
.m 实现篇
1 2 3 4 5 6 7 8 |
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self createSubviews]; } return self; } |
1 2 3 4 5 6 7 8 9 |
- (void)createSubviews { [self.contentView addSubview:self.foodImage]; [self.contentView addSubview:self.nameLabel]; [self.contentView addSubview:self.priceLabel]; [self.contentView addSubview:self.btnMinus]; [self.contentView addSubview:self.btnPlus]; [self.contentView addSubview:self.orderCount]; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
- (UIImageView *)foodImage { if (!_foodImage) { _foodImage = [[UIImageView alloc] init]; } return _foodImage; } - (UILabel *)nameLabel { if (rayon-e ">UILabel *)nameLabel { if (ڄ懒加载. (想了解的看一看). 0.-
.m 实现篇
|