Commit 2e03faa8d8d41415ab9d6cd867609595517617ba
1 parent
7d9b3873
no message
Showing
8 changed files
with
267 additions
and
189 deletions
CNLiveMineModule/Classes/Controller/CNLiveMineController.m
| ... | ... | @@ -44,6 +44,8 @@ static const CGFloat timeValue = 1.5; |
| 44 | 44 | @"name":@"我的订单", |
| 45 | 45 | @"style":@"1", |
| 46 | 46 | @"margin":@"10", |
| 47 | + @"titleHeight":@"50", | |
| 48 | + @"itemHeight":@"60", | |
| 47 | 49 | @"buttons":@[@{ |
| 48 | 50 | @"title":@"订单", |
| 49 | 51 | @"image":@"mine_order" |
| ... | ... | @@ -67,6 +69,8 @@ static const CGFloat timeValue = 1.5; |
| 67 | 69 | @"name":@"常用工具", |
| 68 | 70 | @"style":@"2", |
| 69 | 71 | @"margin":@"10", |
| 72 | + @"titleHeight":@"50", | |
| 73 | + @"itemHeight":@"60", | |
| 70 | 74 | @"buttons":@[@{ |
| 71 | 75 | @"title":@"收货地址", |
| 72 | 76 | @"image":@"mine_address" |
| ... | ... | @@ -103,6 +107,8 @@ static const CGFloat timeValue = 1.5; |
| 103 | 107 | @"pic":@"mine_buy_commodity", |
| 104 | 108 | @"style":@"3", |
| 105 | 109 | @"margin":@"10", |
| 110 | + @"titleHeight":@"50", | |
| 111 | + @"itemHeight":@"80", | |
| 106 | 112 | @"buttons":@[@{ |
| 107 | 113 | @"title":@"电子票", |
| 108 | 114 | @"image":@"mine_e-ticket" |
| ... | ... | @@ -115,6 +121,8 @@ static const CGFloat timeValue = 1.5; |
| 115 | 121 | @"pic":@"mine_china_sport", |
| 116 | 122 | @"style":@"4", |
| 117 | 123 | @"margin":@"10", |
| 124 | + @"titleHeight":@"50", | |
| 125 | + @"itemHeight":@"60", | |
| 118 | 126 | @"buttons":@[@{ |
| 119 | 127 | @"title":@"我的活动", |
| 120 | 128 | @"image":@"mine_activity" |
| ... | ... | @@ -146,6 +154,7 @@ static const CGFloat timeValue = 1.5; |
| 146 | 154 | if(self.soccerBtn){ |
| 147 | 155 | self.soccerBtn.frame = CGRectMake(SCREEN_WIDTH-67-10, SCREEN_HEIGHT-71-10-TabBarHeight, 67, 71); |
| 148 | 156 | } |
| 157 | + [self.tableView reloadData]; | |
| 149 | 158 | } |
| 150 | 159 | |
| 151 | 160 | - (void)viewDidLoad { |
| ... | ... | @@ -161,11 +170,6 @@ static const CGFloat timeValue = 1.5; |
| 161 | 170 | [self loadData]; |
| 162 | 171 | } |
| 163 | 172 | |
| 164 | -- (void)dealloc { | |
| 165 | - | |
| 166 | - | |
| 167 | -} | |
| 168 | - | |
| 169 | 173 | - (void)createSubViews { |
| 170 | 174 | [self.view addSubview:self.tableView]; |
| 171 | 175 | CNLiveMineHeaderView *headerView = [[CNLiveMineHeaderView alloc]initWithFrame:CGRectMake(0, -kHEIGHT, SCREEN_WIDTH, kHEIGHT)]; |
| ... | ... | @@ -199,6 +203,7 @@ static const CGFloat timeValue = 1.5; |
| 199 | 203 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 200 | 204 | |
| 201 | 205 | } |
| 206 | + | |
| 202 | 207 | #pragma mark - CNLiveMineHeaderViewDelegate |
| 203 | 208 | - (void)headerView:(CNLiveMineHeaderView *)headerView pushToController:(CNLiveMineHeaderViewType)type{ |
| 204 | 209 | switch (type) { |
| ... | ... | @@ -253,66 +258,65 @@ static const CGFloat timeValue = 1.5; |
| 253 | 258 | } |
| 254 | 259 | |
| 255 | 260 | #pragma mark - CNLiveMineCellDelegate |
| 256 | -- (void)cell:(CNLiveMineCell *)cell clickedButtonWithType:(CNLiveMineCellType)type tag:(NSInteger)tag{ | |
| 257 | - switch (type) { | |
| 261 | +- (void)cell:(CNLiveMineCell *)cell didSelectItemAtItem:(NSInteger)item{ | |
| 262 | + switch (cell.model.type) { | |
| 258 | 263 | case CNLiveMineCellTypeOrder: |
| 259 | 264 | { |
| 260 | - if(tag-10000 == 4){ | |
| 265 | + if(item == 4){ | |
| 261 | 266 | //售后 |
| 262 | 267 | id<CNLiveOrderServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveOrderServiceProtocol)]; |
| 263 | 268 | [service pushToRefundViewController:0]; |
| 264 | 269 | |
| 265 | 270 | }else{ |
| 266 | 271 | id<CNLiveOrderServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveOrderServiceProtocol)]; |
| 267 | - [service pushToOrderViewController:tag-10000]; | |
| 272 | + [service pushToOrderViewController:item]; | |
| 268 | 273 | } |
| 269 | 274 | } |
| 270 | 275 | break; |
| 271 | 276 | case CNLiveMineCellTypeTool: |
| 272 | 277 | { |
| 273 | - if(tag == 10000){ | |
| 278 | + if(item == 0){ | |
| 274 | 279 | // 收货地址 |
| 275 | 280 | id<CNLiveOrderServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveOrderServiceProtocol)]; |
| 276 | 281 | [service pushToAddressViewController]; |
| 277 | 282 | } |
| 278 | - else if(tag == 10001){ | |
| 283 | + else if(item == 1){ | |
| 279 | 284 | // 余额 |
| 280 | 285 | // XWBalanceController *vc = [[XWBalanceController alloc]init]; |
| 281 | 286 | // [self.navigationController pushViewController:vc animated:YES]; |
| 282 | 287 | } |
| 283 | - else if(tag == 10002){ | |
| 288 | + else if(item == 2){ | |
| 284 | 289 | // 收藏 |
| 285 | 290 | id<CNLiveCollectionServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveCollectionServiceProtocol)]; |
| 286 | 291 | [service pushToCollectionViewController]; |
| 287 | 292 | } |
| 288 | - else if(tag == 10003){ | |
| 293 | + else if(item == 3){ | |
| 289 | 294 | // 发布记录 |
| 290 | 295 | // XWOrdersController *vc = [[XWOrdersController alloc]init]; |
| 291 | 296 | // [self.navigationController pushViewController:vc animated:YES]; |
| 292 | 297 | } |
| 293 | - else if(tag == 10004){ | |
| 298 | + else if(item == 4){ | |
| 294 | 299 | // 邀请好友 |
| 295 | 300 | // XWOrdersController *vc = [[XWOrdersController alloc]init]; |
| 296 | 301 | // [self.navigationController pushViewController:vc animated:YES]; |
| 297 | 302 | } |
| 298 | - else if(tag == 10005){ | |
| 303 | + else if(item == 5){ | |
| 299 | 304 | // 设置 |
| 300 | 305 | id<CNLiveSettingServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveSettingServiceProtocol)]; |
| 301 | 306 | [service pushToSettingViewController]; |
| 302 | 307 | } |
| 303 | - else if(tag == 10006){ | |
| 308 | + else if(item == 6){ | |
| 304 | 309 | // 小家音响 |
| 305 | 310 | |
| 306 | 311 | } |
| 307 | - else if(tag == 10007){ | |
| 312 | + else if(item == 7){ | |
| 308 | 313 | // 我的礼盒 |
| 309 | 314 | id<CNLiveOrderServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveOrderServiceProtocol)]; |
| 310 | 315 | [service pushToGiftBoxViewController]; |
| 311 | 316 | } |
| 312 | - else if(tag == 10008){ | |
| 317 | + else if(item == 8){ | |
| 313 | 318 | // 路径工具 |
| 314 | -// XWOrdersController *vc = [[XWOrdersController alloc]init]; | |
| 315 | -// [self.navigationController pushViewController:vc animated:YES]; | |
| 319 | + | |
| 316 | 320 | } |
| 317 | 321 | |
| 318 | 322 | } |
| ... | ... | @@ -324,11 +328,11 @@ static const CGFloat timeValue = 1.5; |
| 324 | 328 | break; |
| 325 | 329 | case CNLiveMineCellTypeSports: |
| 326 | 330 | { |
| 327 | - if(tag == 10000){ | |
| 331 | + if(item == 0){ | |
| 328 | 332 | // 我的活动 |
| 329 | 333 | |
| 330 | 334 | } |
| 331 | - else if(tag == 10001){ | |
| 335 | + else if(item == 1){ | |
| 332 | 336 | // 我的记录 |
| 333 | 337 | |
| 334 | 338 | } | ... | ... |
CNLiveMineModule/Classes/Model/CNLiveMineModel.h
| ... | ... | @@ -34,6 +34,10 @@ typedef NS_ENUM(NSInteger, CNLiveMineCellType) { |
| 34 | 34 | @property (nonatomic, assign) CNLiveMineCellType type; |
| 35 | 35 | |
| 36 | 36 | @property (nonatomic, assign) CGFloat height; |
| 37 | +// title的高度 | |
| 38 | +@property (nonatomic, assign) CGFloat titleHeight; | |
| 39 | +// UICollectionView一个item的高度 | |
| 40 | +@property (nonatomic, assign) CGFloat itemHeight; | |
| 37 | 41 | @property (nonatomic, assign) CGFloat margin; |
| 38 | 42 | |
| 39 | 43 | // 是否显示路径工具 | ... | ... |
CNLiveMineModule/Classes/Model/CNLiveMineModel.m
| ... | ... | @@ -46,27 +46,24 @@ static const NSInteger margin = 10; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | - (CGFloat)height{ |
| 49 | - CGFloat titleHeight = 50; | |
| 50 | - CGFloat btnHeight = 60; | |
| 51 | - | |
| 52 | 49 | //订单 |
| 53 | 50 | if(self.type == CNLiveMineCellTypeOrder){ |
| 54 | - return 2*margin+titleHeight+btnHeight+margin; | |
| 51 | + return 2*margin+self.titleHeight+self.itemHeight+margin; | |
| 55 | 52 | } |
| 56 | 53 | //工具 |
| 57 | 54 | else if(self.type == CNLiveMineCellTypeTool){ |
| 58 | - return 2*margin+titleHeight+ceilf(self.buttons.count/4.0)*(btnHeight+margin); | |
| 55 | + return 2*margin+self.titleHeight+ceilf(self.buttons.count/4.0)*(self.itemHeight+margin); | |
| 59 | 56 | |
| 60 | 57 | } |
| 61 | 58 | //商品 |
| 62 | 59 | else if(self.type == CNLiveMineCellTypeGoods){ |
| 63 | 60 | // 电票的高度 80 |
| 64 | - return 2*margin+titleHeight+80+margin; | |
| 61 | + return 2*margin+self.titleHeight+self.itemHeight+margin; | |
| 65 | 62 | |
| 66 | 63 | } |
| 67 | 64 | //大众体育 |
| 68 | 65 | else if(self.type == CNLiveMineCellTypeSports){ |
| 69 | - return 2*margin+titleHeight+ceilf(self.buttons.count/4.0)*(btnHeight+margin); | |
| 66 | + return 2*margin+self.titleHeight+ceilf(self.buttons.count/4.0)*(self.itemHeight+margin); | |
| 70 | 67 | |
| 71 | 68 | } |
| 72 | 69 | return 0.0000001f; | ... | ... |
CNLiveMineModule/Classes/View/CNLiveMineButtonCell.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveMineButtonCell.h | |
| 3 | +// CNLiveMineModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | + | |
| 11 | +NS_ASSUME_NONNULL_BEGIN | |
| 12 | +@class CNLiveMineButtonModel; | |
| 13 | + | |
| 14 | +static NSString * const kCNLiveMineButtonCell = @"CNLiveMineButtonCell"; | |
| 15 | + | |
| 16 | +@interface CNLiveMineButtonCell : UICollectionViewCell | |
| 17 | +@property (nonatomic, strong) CNLiveMineButtonModel *model; | |
| 18 | + | |
| 19 | +@end | |
| 20 | + | |
| 21 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveMineModule/Classes/View/CNLiveMineButtonCell.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveMineButtonCell.m | |
| 3 | +// CNLiveMineModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveMineButtonCell.h" | |
| 10 | +#import <Masonry/Masonry.h> | |
| 11 | +#import "QMUIKit.h" | |
| 12 | +#import "CNLiveCategory.h" | |
| 13 | +#import "CNLiveBaseKit.h" | |
| 14 | +#import "CNLiveMineModel.h" | |
| 15 | + | |
| 16 | +@interface CNLiveMineButtonCell() | |
| 17 | +@property (nonatomic, strong) UIImageView *image; | |
| 18 | +@property (nonatomic, strong) UILabel *title; | |
| 19 | + | |
| 20 | +@end | |
| 21 | + | |
| 22 | +@implementation CNLiveMineButtonCell | |
| 23 | +#pragma mark - 生命周期 | |
| 24 | +- (id)initWithFrame:(CGRect)frame { | |
| 25 | + self = [super initWithFrame:frame]; | |
| 26 | + if (self) { | |
| 27 | + self.contentView.backgroundColor = [UIColor whiteColor]; | |
| 28 | + [self.contentView addSubview:self.image]; | |
| 29 | + [self.contentView addSubview:self.title]; | |
| 30 | + } | |
| 31 | + return self; | |
| 32 | +} | |
| 33 | + | |
| 34 | +- (void)layoutSubviews{ | |
| 35 | + [super layoutSubviews]; | |
| 36 | + [_image mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 37 | + make.left.equalTo(self.contentView.mas_left); | |
| 38 | + make.right.equalTo(self.contentView.mas_right); | |
| 39 | + make.top.equalTo(self.contentView.mas_top); | |
| 40 | + make.height.offset(self.frame.size.height*2/3.0); | |
| 41 | + | |
| 42 | + }]; | |
| 43 | + [_title mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 44 | + make.top.equalTo(self.image.mas_bottom); | |
| 45 | + make.left.equalTo(self.image.mas_left); | |
| 46 | + make.right.equalTo(self.image.mas_right); | |
| 47 | + make.bottom.equalTo(self.contentView.mas_bottom); | |
| 48 | + | |
| 49 | + }]; | |
| 50 | + | |
| 51 | +} | |
| 52 | + | |
| 53 | +#pragma mark - 数据 | |
| 54 | +- (void)setModel:(CNLiveMineButtonModel *)model{ | |
| 55 | + UIImage *xw_image = [self getImageWithImageName:model.image bundleName:@"CNLiveMineModule" targetClass:[self class]]; | |
| 56 | + _image.image = xw_image; | |
| 57 | + _title.text = model.title; | |
| 58 | + _title.font = UIFontCNMake(12.0); | |
| 59 | +} | |
| 60 | + | |
| 61 | +- (void)awakeFromNib { | |
| 62 | + [super awakeFromNib]; | |
| 63 | + // Initialization code | |
| 64 | +} | |
| 65 | + | |
| 66 | +#pragma mark - 懒加载 | |
| 67 | +- (UIImageView *)image{ | |
| 68 | + if (!_image) { | |
| 69 | + _image = [[UIImageView alloc] init]; | |
| 70 | + _image.contentMode = UIViewContentModeCenter; | |
| 71 | + } | |
| 72 | + return _image; | |
| 73 | +} | |
| 74 | + | |
| 75 | +- (UILabel *)title { | |
| 76 | + if (!_title) { | |
| 77 | + _title = [[UILabel alloc] init]; | |
| 78 | + _title.userInteractionEnabled = YES; | |
| 79 | + _title.numberOfLines = 1; | |
| 80 | + _title.lineBreakMode = NSLineBreakByTruncatingTail; | |
| 81 | + _title.textColor = [UIColor blackColor]; | |
| 82 | + _title.textAlignment = NSTextAlignmentCenter; | |
| 83 | + _title.font = UIFontCNMake(12.0); | |
| 84 | + } | |
| 85 | + return _title; | |
| 86 | +} | |
| 87 | + | |
| 88 | +@end | ... | ... |
CNLiveMineModule/Classes/View/CNLiveMineCell.h
| ... | ... | @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN |
| 15 | 15 | static NSString * const kCNLiveMineCell = @"CNLiveMineCell"; |
| 16 | 16 | @protocol CNLiveMineCellDelegate <NSObject> |
| 17 | 17 | @optional |
| 18 | -- (void)cell:(CNLiveMineCell *)cell clickedButtonWithType:(CNLiveMineCellType)type tag:(NSInteger)tag; | |
| 18 | +- (void)cell:(CNLiveMineCell *)cell didSelectItemAtItem:(NSInteger)item; | |
| 19 | 19 | |
| 20 | 20 | @end |
| 21 | 21 | ... | ... |
CNLiveMineModule/Classes/View/CNLiveMineCell.m
| ... | ... | @@ -11,87 +11,110 @@ |
| 11 | 11 | #import "QMUIKit.h" |
| 12 | 12 | #import "CNLiveCategory.h" |
| 13 | 13 | #import "CNLiveBaseKit.h" |
| 14 | +#import "CNLiveMineButtonCell.h" | |
| 14 | 15 | |
| 15 | -@interface CNLiveMineCell() | |
| 16 | +@interface CNLiveMineCell()<UICollectionViewDelegate, UICollectionViewDataSource> | |
| 16 | 17 | @property (nonatomic, strong) UIView *bgView; |
| 17 | 18 | @property (nonatomic, strong) UIButton *titleButton; |
| 18 | 19 | @property (nonatomic, strong) UIButton *allButton; |
| 19 | 20 | |
| 20 | 21 | @property (nonatomic, strong) UIView *line; |
| 22 | +@property (nonatomic, strong) NSMutableArray *buttons; | |
| 23 | + | |
| 24 | +@property (nonatomic, strong) UICollectionView *collectionView; | |
| 21 | 25 | |
| 22 | 26 | @end |
| 23 | 27 | |
| 24 | 28 | @implementation CNLiveMineCell |
| 29 | + | |
| 25 | 30 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ |
| 26 | 31 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; |
| 27 | 32 | if (self) { |
| 28 | 33 | self.contentView.backgroundColor = [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:1.0]; |
| 29 | - [self xw_layoutSubviews]; | |
| 34 | + [self createSubviews]; | |
| 30 | 35 | } |
| 31 | 36 | return self; |
| 32 | 37 | } |
| 33 | 38 | |
| 34 | -- (void)xw_layoutSubviews{ | |
| 39 | +- (void)createSubviews{ | |
| 35 | 40 | [self.contentView addSubview:self.bgView]; |
| 36 | 41 | [self.contentView addSubview:self.titleButton]; |
| 37 | 42 | [self.contentView addSubview:self.allButton]; |
| 38 | 43 | [self.contentView addSubview:self.line]; |
| 39 | - | |
| 44 | + [self.contentView addSubview:self.collectionView]; | |
| 45 | + | |
| 40 | 46 | } |
| 41 | 47 | |
| 42 | 48 | - (void)setModel:(CNLiveMineModel *)model{ |
| 43 | - if(_model == model){ | |
| 44 | - return; | |
| 45 | - } | |
| 46 | 49 | _model = model; |
| 50 | + | |
| 47 | 51 | [_titleButton setTitle:model.name forState:UIControlStateNormal]; |
| 52 | + _titleButton.titleLabel.font = UIFontBoldCNMake(15.0); | |
| 53 | + | |
| 48 | 54 | UIImage *xw_image = [self getImageWithImageName:model.pic bundleName:@"CNLiveMineModule" targetClass:[CNLiveMineCell class]]; |
| 49 | 55 | [_titleButton setImage:xw_image forState:UIControlStateNormal]; |
| 56 | + | |
| 50 | 57 | _allButton.hidden = YES; |
| 51 | - | |
| 58 | + _allButton.titleLabel.font = UIFontCNMake(12.0); | |
| 59 | + | |
| 60 | + [_bgView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 61 | + make.left.equalTo(self.contentView.mas_left).with.offset(self.model.margin); | |
| 62 | + make.right.equalTo(self.contentView.mas_right).with.offset(-self.model.margin); | |
| 63 | + make.top.equalTo(self.contentView.mas_top).with.offset(0); | |
| 64 | + make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-self.model.margin); | |
| 65 | + | |
| 66 | + }]; | |
| 52 | 67 | switch (model.type) { |
| 53 | 68 | case CNLiveMineCellTypeOrder: |
| 54 | 69 | { |
| 55 | 70 | [self order_layoutSubviews]; |
| 56 | 71 | } |
| 57 | 72 | break; |
| 58 | - | |
| 73 | + | |
| 59 | 74 | case CNLiveMineCellTypeTool: |
| 60 | 75 | { |
| 61 | 76 | [self tool_layoutSubviews]; |
| 62 | 77 | } |
| 63 | 78 | break; |
| 64 | - | |
| 79 | + | |
| 65 | 80 | case CNLiveMineCellTypeGoods: |
| 66 | 81 | { |
| 67 | 82 | [self goods_layoutSubviews]; |
| 68 | 83 | } |
| 69 | 84 | break; |
| 70 | - | |
| 85 | + | |
| 71 | 86 | case CNLiveMineCellTypeSports: |
| 72 | 87 | { |
| 73 | 88 | [self sports_layoutSubviews]; |
| 74 | 89 | } |
| 75 | 90 | break; |
| 76 | 91 | } |
| 92 | + [_line mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 93 | + make.top.equalTo(self.titleButton.mas_bottom).with.offset(0); | |
| 94 | + make.left.equalTo(self.bgView.mas_left).with.offset(self.model.margin); | |
| 95 | + make.right.equalTo(self.bgView.mas_right).with.offset(-self.model.margin); | |
| 96 | + make.height.with.offset(0.5); | |
| 97 | + | |
| 98 | + }]; | |
| 99 | + [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 100 | + make.top.equalTo(self.line.mas_bottom); | |
| 101 | + make.left.equalTo(self.bgView.mas_left).with.offset(self.model.margin); | |
| 102 | + make.right.equalTo(self.bgView.mas_right).with.offset(-self.model.margin); | |
| 103 | + make.bottom.equalTo(self.bgView.mas_bottom); | |
| 104 | + }]; | |
| 105 | + [_collectionView reloadData]; | |
| 106 | + | |
| 77 | 107 | } |
| 78 | 108 | |
| 79 | 109 | - (void)order_layoutSubviews{ |
| 80 | - [_bgView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 81 | - make.left.equalTo(self.contentView.mas_left).with.offset(self.model.margin); | |
| 82 | - make.right.equalTo(self.contentView.mas_right).with.offset(-self.model.margin); | |
| 83 | - make.top.equalTo(self.contentView.mas_top).with.offset(0); | |
| 84 | - make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-self.model.margin); | |
| 85 | - | |
| 86 | - }]; | |
| 87 | 110 | [_titleButton setImage:nil forState:UIControlStateNormal]; |
| 88 | 111 | _titleButton.titleLabel.textAlignment = NSTextAlignmentLeft; |
| 89 | 112 | _titleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//使图片和文字水平居中显示 |
| 90 | 113 | [_titleButton mas_makeConstraints:^(MASConstraintMaker *make) { |
| 91 | - make.top.equalTo(self.bgView.mas_top).with.offset(0); | |
| 114 | + make.top.equalTo(self.bgView.mas_top); | |
| 92 | 115 | make.left.equalTo(self.bgView.mas_left).with.offset(self.model.margin); |
| 93 | 116 | make.right.equalTo(self.bgView.mas_right).with.offset(-self.model.margin); |
| 94 | - make.height.with.offset(50); | |
| 117 | + make.height.with.offset(self.model.titleHeight); | |
| 95 | 118 | |
| 96 | 119 | }]; |
| 97 | 120 | |
| ... | ... | @@ -99,38 +122,12 @@ |
| 99 | 122 | [_allButton mas_makeConstraints:^(MASConstraintMaker *make) { |
| 100 | 123 | make.top.equalTo(self.titleButton.mas_top); |
| 101 | 124 | make.right.equalTo(self.bgView.mas_right).with.offset(-self.model.margin); |
| 102 | - make.height.with.offset(50); | |
| 125 | + make.height.with.offset(self.model.titleHeight); | |
| 103 | 126 | |
| 104 | 127 | }]; |
| 105 | 128 | |
| 106 | - [_line mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 107 | - make.top.equalTo(self.titleButton.mas_bottom).with.offset(0); | |
| 108 | - make.left.equalTo(self.bgView.mas_left).with.offset(self.model.margin); | |
| 109 | - make.right.equalTo(self.bgView.mas_right).with.offset(-self.model.margin); | |
| 110 | - make.height.with.offset(0.5); | |
| 111 | - | |
| 112 | - }]; | |
| 113 | - | |
| 114 | - CGFloat width = SCREEN_WIDTH-2*self.model.margin; | |
| 115 | - CGFloat btnWidth = width/self.model.buttons.count*1.0; | |
| 116 | - CGFloat btnHeight = 60; | |
| 117 | - | |
| 118 | - for(int i = 0; i < self.model.buttons.count; i++){ | |
| 119 | - CNLiveMineButtonModel *buttonModel = self.model.buttons[i]; | |
| 120 | - UIButton *btn = [self createButtonWithFrame:CGRectMake(self.model.margin+btnWidth*i, 50+self.model.margin, btnWidth, btnHeight) title:buttonModel.title image:buttonModel.image tag:10000+i]; | |
| 121 | - [self addSubview:btn]; | |
| 122 | - | |
| 123 | - } | |
| 124 | - | |
| 125 | 129 | } |
| 126 | 130 | - (void)tool_layoutSubviews{ |
| 127 | - [_bgView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 128 | - make.left.equalTo(self.contentView.mas_left).with.offset(self.model.margin); | |
| 129 | - make.right.equalTo(self.contentView.mas_right).with.offset(-self.model.margin); | |
| 130 | - make.top.equalTo(self.contentView.mas_top).with.offset(0); | |
| 131 | - make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-self.model.margin); | |
| 132 | - | |
| 133 | - }]; | |
| 134 | 131 | [_titleButton setImage:nil forState:UIControlStateNormal]; |
| 135 | 132 | _titleButton.titleLabel.textAlignment = NSTextAlignmentLeft; |
| 136 | 133 | _titleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//使图片和文字水平居中显示 |
| ... | ... | @@ -138,115 +135,41 @@ |
| 138 | 135 | make.top.equalTo(self.bgView.mas_top).with.offset(0); |
| 139 | 136 | make.left.equalTo(self.bgView.mas_left).with.offset(self.model.margin); |
| 140 | 137 | make.right.equalTo(self.bgView.mas_right).with.offset(-self.model.margin); |
| 141 | - make.height.with.offset(50); | |
| 142 | - | |
| 143 | - }]; | |
| 144 | - _allButton.hidden = YES; | |
| 145 | - | |
| 146 | - [_line mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 147 | - make.top.equalTo(self.titleButton.mas_bottom).with.offset(0); | |
| 148 | - make.left.equalTo(self.bgView.mas_left).with.offset(self.model.margin); | |
| 149 | - make.right.equalTo(self.bgView.mas_right).with.offset(-self.model.margin); | |
| 150 | - make.height.with.offset(0.5); | |
| 138 | + make.height.with.offset(self.model.titleHeight); | |
| 151 | 139 | |
| 152 | 140 | }]; |
| 153 | - | |
| 154 | - CGFloat width = SCREEN_WIDTH-2*self.model.margin; | |
| 155 | - | |
| 156 | - CGFloat btnWidth = width/4.0; | |
| 157 | - CGFloat btnHeight = 60; | |
| 158 | 141 | |
| 159 | - for(int i = 0; i < self.model.buttons.count; i++){ | |
| 160 | - CNLiveMineButtonModel *buttonModel = self.model.buttons[i]; | |
| 161 | - NSInteger row = i % 4; | |
| 162 | - NSInteger col = floorf(i / 4.0); | |
| 163 | - UIButton *btn = [self createButtonWithFrame:CGRectMake(self.model.margin+btnWidth*row, (col*(btnHeight+self.model.margin))+50+self.model.margin, btnWidth, btnHeight) title:buttonModel.title image:buttonModel.image tag:10000+i]; | |
| 164 | - [self addSubview:btn]; | |
| 165 | - | |
| 166 | - } | |
| 167 | 142 | } |
| 168 | 143 | - (void)goods_layoutSubviews{ |
| 169 | 144 | [_titleButton setImageEdgeInsets:UIEdgeInsetsMake(0, -self.model.margin, 0, 0)]; |
| 170 | 145 | [_titleButton setTitleEdgeInsets:UIEdgeInsetsMake(0, self.model.margin, 0, 0)]; |
| 171 | 146 | |
| 172 | - [_bgView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 173 | - make.left.equalTo(self.contentView.mas_left).with.offset(self.model.margin); | |
| 174 | - make.right.equalTo(self.contentView.mas_right).with.offset(-self.model.margin); | |
| 175 | - make.top.equalTo(self.contentView.mas_top).with.offset(0); | |
| 176 | - make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-self.model.margin); | |
| 177 | - | |
| 178 | - }]; | |
| 179 | 147 | _titleButton.titleLabel.textAlignment = NSTextAlignmentCenter; |
| 180 | 148 | _titleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示 |
| 181 | 149 | [_titleButton mas_makeConstraints:^(MASConstraintMaker *make) { |
| 182 | 150 | make.top.equalTo(self.bgView.mas_top).with.offset(0); |
| 183 | 151 | make.left.equalTo(self.bgView.mas_left).with.offset(self.model.margin); |
| 184 | 152 | make.right.equalTo(self.bgView.mas_right).with.offset(-self.model.margin); |
| 185 | - make.height.with.offset(50); | |
| 153 | + make.height.with.offset(self.model.titleHeight); | |
| 186 | 154 | |
| 187 | 155 | }]; |
| 188 | - _allButton.hidden = YES; | |
| 189 | - | |
| 190 | - [_line mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 191 | - make.top.equalTo(self.titleButton.mas_bottom).with.offset(0); | |
| 192 | - make.left.equalTo(self.bgView.mas_left).with.offset(self.model.margin); | |
| 193 | - make.right.equalTo(self.bgView.mas_right).with.offset(-self.model.margin); | |
| 194 | - make.height.with.offset(0.5); | |
| 195 | - | |
| 196 | - }]; | |
| 197 | - CGFloat width = SCREEN_WIDTH-2*self.model.margin; | |
| 198 | - CGFloat btnWidth = width/4.0; | |
| 199 | - CGFloat btnHeight = 80; | |
| 200 | - | |
| 201 | - // 电子票 | |
| 202 | - CNLiveMineButtonModel *buttonModel = self.model.buttons[0]; | |
| 203 | - UIButton *btn = [self createButtonWithFrame:CGRectMake((width-btnWidth)/2.0, self.model.margin+50, btnWidth, btnHeight) title:buttonModel.title image:buttonModel.image tag:10000]; | |
| 204 | - [self addSubview:btn]; | |
| 205 | 156 | |
| 206 | 157 | } |
| 158 | + | |
| 207 | 159 | - (void)sports_layoutSubviews{ |
| 208 | 160 | [_titleButton setImageEdgeInsets:UIEdgeInsetsMake(0, -self.model.margin, 0, 0)]; |
| 209 | 161 | [_titleButton setTitleEdgeInsets:UIEdgeInsetsMake(0, self.model.margin, 0, 0)]; |
| 210 | 162 | |
| 211 | - [_bgView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 212 | - make.left.equalTo(self.contentView.mas_left).with.offset(self.model.margin); | |
| 213 | - make.right.equalTo(self.contentView.mas_right).with.offset(-self.model.margin); | |
| 214 | - make.top.equalTo(self.contentView.mas_top).with.offset(0); | |
| 215 | - make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-self.model.margin); | |
| 216 | - | |
| 217 | - }]; | |
| 218 | 163 | _titleButton.titleLabel.textAlignment = NSTextAlignmentCenter; |
| 219 | 164 | _titleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示 |
| 220 | 165 | [_titleButton mas_makeConstraints:^(MASConstraintMaker *make) { |
| 221 | 166 | make.top.equalTo(self.bgView.mas_top).with.offset(0); |
| 222 | 167 | make.left.equalTo(self.bgView.mas_left).with.offset(self.model.margin); |
| 223 | 168 | make.right.equalTo(self.bgView.mas_right).with.offset(-self.model.margin); |
| 224 | - make.height.with.offset(50); | |
| 225 | - | |
| 226 | - }]; | |
| 227 | - _allButton.hidden = YES; | |
| 228 | - | |
| 229 | - [_line mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 230 | - make.top.equalTo(self.titleButton.mas_bottom).with.offset(0); | |
| 231 | - make.left.equalTo(self.bgView.mas_left).with.offset(self.model.margin); | |
| 232 | - make.right.equalTo(self.bgView.mas_right).with.offset(-self.model.margin); | |
| 233 | - make.height.with.offset(0.5); | |
| 169 | + make.height.with.offset(self.model.titleHeight); | |
| 234 | 170 | |
| 235 | 171 | }]; |
| 236 | 172 | |
| 237 | - CGFloat width = SCREEN_WIDTH-2*self.model.margin; | |
| 238 | - | |
| 239 | - CGFloat btnWidth = width/4.0; | |
| 240 | - CGFloat btnHeight = 60; | |
| 241 | - | |
| 242 | - for(int i = 0; i < self.model.buttons.count; i++){ | |
| 243 | - CNLiveMineButtonModel *buttonModel = self.model.buttons[i]; | |
| 244 | - NSInteger row = i % 4; | |
| 245 | - NSInteger col = floorf(i / 4.0); | |
| 246 | - UIButton *btn = [self createButtonWithFrame:CGRectMake(self.model.margin+btnWidth*row, (col*(btnHeight+self.model.margin))+50+self.model.margin, btnWidth, btnHeight) title:buttonModel.title image:buttonModel.image tag:10000+i]; | |
| 247 | - [self addSubview:btn]; | |
| 248 | - | |
| 249 | - } | |
| 250 | 173 | } |
| 251 | 174 | |
| 252 | 175 | - (void)awakeFromNib { |
| ... | ... | @@ -261,20 +184,20 @@ |
| 261 | 184 | } |
| 262 | 185 | |
| 263 | 186 | #pragma mark - 响应方法 |
| 264 | -- (void)btnDidClicked:(UIButton *)btn{ | |
| 265 | - if (self.delegate && [self.delegate respondsToSelector:@selector(cell:clickedButtonWithType:tag:)]) { | |
| 266 | - [self.delegate cell:self clickedButtonWithType:self.model.type tag:btn.tag]; | |
| 187 | +- (void)allDidClicked:(UIButton *)btn{ | |
| 188 | + if (self.delegate && [self.delegate respondsToSelector:@selector(cell:didSelectItemAtItem:)]) { | |
| 189 | + [self.delegate cell:self didSelectItemAtItem:0]; | |
| 267 | 190 | } |
| 268 | 191 | } |
| 269 | 192 | |
| 270 | -- (void)allDidClicked:(UIButton *)btn{ | |
| 271 | - if (self.delegate && [self.delegate respondsToSelector:@selector(cell:clickedButtonWithType:tag:)]) { | |
| 272 | - [self.delegate cell:self clickedButtonWithType:CNLiveMineCellTypeOrder tag:10000]; | |
| 193 | +#pragma mark - 懒加载 | |
| 194 | +- (NSMutableArray *)buttons { | |
| 195 | + if (!_buttons) { | |
| 196 | + _buttons = [NSMutableArray array]; | |
| 273 | 197 | } |
| 274 | - | |
| 198 | + return _buttons; | |
| 275 | 199 | } |
| 276 | 200 | |
| 277 | -#pragma mark - 懒加载 | |
| 278 | 201 | - (UIView *)bgView{ |
| 279 | 202 | if (!_bgView) { |
| 280 | 203 | _bgView = [[UIView alloc] init]; |
| ... | ... | @@ -284,10 +207,11 @@ |
| 284 | 207 | } |
| 285 | 208 | return _bgView; |
| 286 | 209 | } |
| 210 | + | |
| 287 | 211 | - (UIButton *)titleButton{ |
| 288 | 212 | if (!_titleButton) { |
| 289 | 213 | _titleButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
| 290 | - _titleButton.titleLabel.font = [UIFont boldSystemFontOfSize:16]; | |
| 214 | + _titleButton.titleLabel.font = UIFontBoldCNMake(15.0); | |
| 291 | 215 | [_titleButton setTitleColor:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0] forState:UIControlStateNormal]; |
| 292 | 216 | _titleButton.adjustsImageWhenHighlighted = NO; |
| 293 | 217 | } |
| ... | ... | @@ -302,7 +226,7 @@ |
| 302 | 226 | UIImage *xw_image = [self getImageWithImageName:@"mine_all_front" bundleName:@"CNLiveMineModule" targetClass:[CNLiveMineCell class]]; |
| 303 | 227 | [_allButton setImage:xw_image forState:UIControlStateNormal]; |
| 304 | 228 | [_allButton setImage:xw_image forState:UIControlStateHighlighted]; |
| 305 | - _allButton.titleLabel.font = [UIFont systemFontOfSize:12]; | |
| 229 | + _allButton.titleLabel.font = UIFontCNMake(12.0); | |
| 306 | 230 | [_allButton setTitleColor:[UIColor colorWithRed:190.0/255.0 green:190.0/255.0 blue:190.0/255.0 alpha:1.0] forState:UIControlStateNormal]; |
| 307 | 231 | _allButton.adjustsImageWhenHighlighted = NO; |
| 308 | 232 | [_allButton addTarget:self action:@selector(allDidClicked:) forControlEvents:UIControlEventTouchUpInside]; |
| ... | ... | @@ -322,25 +246,69 @@ |
| 322 | 246 | return _line; |
| 323 | 247 | } |
| 324 | 248 | |
| 325 | -#pragma mark - 私有方法 | |
| 326 | -- (UIButton *)createButtonWithFrame:(CGRect)frame title:(NSString *)title image:(NSString *)image tag:(NSInteger)tag{ | |
| 327 | - UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 328 | - btn.tag = tag; | |
| 329 | - btn.frame = frame; | |
| 330 | - btn.titleLabel.font = [UIFont systemFontOfSize:13]; | |
| 331 | - btn.titleLabel.textAlignment = NSTextAlignmentCenter; | |
| 332 | - btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示 | |
| 333 | - | |
| 334 | - [btn setTitle:title forState:UIControlStateNormal]; | |
| 335 | - [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; | |
| 336 | - UIImage *xw_image = [self getImageWithImageName:image bundleName:@"CNLiveMineModule" targetClass:[CNLiveMineCell class]]; | |
| 337 | - [btn setImage:xw_image forState:UIControlStateNormal]; | |
| 338 | - btn.adjustsImageWhenHighlighted = NO; | |
| 339 | - [btn addTarget:self action:@selector(btnDidClicked:) forControlEvents:UIControlEventTouchUpInside]; | |
| 340 | - btn.titleEdgeInsets = UIEdgeInsetsMake(btn.imageView.frame.size.height+self.model.margin, -btn.imageView.frame.size.width, 0, 0); | |
| 341 | - btn.imageEdgeInsets = UIEdgeInsetsMake(-btn.titleLabel.bounds.size.height, 0, self.model.margin, -btn.titleLabel.bounds.size.width); | |
| 342 | - return btn; | |
| 343 | - | |
| 249 | +- (UICollectionView *)collectionView{ | |
| 250 | + if(!_collectionView){ | |
| 251 | + UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; | |
| 252 | + //设置CollectionView的属性 | |
| 253 | + _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-2*self.model.margin, self.model.height-(50+self.model.margin)) collectionViewLayout:flowLayout]; | |
| 254 | + _collectionView.delegate = self; | |
| 255 | + _collectionView.dataSource = self; | |
| 256 | + _collectionView.scrollEnabled = NO; | |
| 257 | + _collectionView.backgroundColor = [UIColor clearColor]; | |
| 258 | + _collectionView.showsVerticalScrollIndicator = NO; | |
| 259 | + _collectionView.showsHorizontalScrollIndicator = NO; | |
| 260 | + [_collectionView registerClass:[CNLiveMineButtonCell class] forCellWithReuseIdentifier:kCNLiveMineButtonCell]; | |
| 261 | + } | |
| 262 | + return _collectionView; | |
| 263 | +} | |
| 264 | + | |
| 265 | +#pragma mark - 代理 | |
| 266 | +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { | |
| 267 | + switch (self.model.type) { | |
| 268 | + case CNLiveMineCellTypeOrder: | |
| 269 | + { | |
| 270 | + return CGSizeMake((SCREEN_WIDTH-4*self.model.margin-4*self.model.margin)/5.0, self.model.itemHeight); | |
| 271 | + } | |
| 272 | + break; | |
| 273 | + | |
| 274 | + case CNLiveMineCellTypeTool: | |
| 275 | + { | |
| 276 | + return CGSizeMake((SCREEN_WIDTH-4*self.model.margin-3*self.model.margin)/4.0, self.model.itemHeight); | |
| 277 | + } | |
| 278 | + break; | |
| 279 | + | |
| 280 | + case CNLiveMineCellTypeGoods: | |
| 281 | + { | |
| 282 | + return CGSizeMake(SCREEN_WIDTH-4*self.model.margin, self.model.itemHeight); | |
| 283 | + } | |
| 284 | + break; | |
| 285 | + | |
| 286 | + case CNLiveMineCellTypeSports: | |
| 287 | + { | |
| 288 | + return CGSizeMake((SCREEN_WIDTH-4*self.model.margin-3*self.model.margin)/4.0, self.model.itemHeight); | |
| 289 | + } | |
| 290 | + break; | |
| 291 | + } | |
| 292 | +} | |
| 293 | + | |
| 294 | +- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { | |
| 295 | + return UIEdgeInsetsMake(self.model.margin, 0, self.model.margin, 0); | |
| 296 | +} | |
| 297 | + | |
| 298 | +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { | |
| 299 | + return self.model.buttons.count; | |
| 300 | +} | |
| 301 | + | |
| 302 | +- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { | |
| 303 | + CNLiveMineButtonCell *cell = (CNLiveMineButtonCell *)[collectionView dequeueReusableCellWithReuseIdentifier:kCNLiveMineButtonCell forIndexPath:indexPath]; | |
| 304 | + cell.model = self.model.buttons[indexPath.row]; | |
| 305 | + return cell; | |
| 306 | +} | |
| 307 | + | |
| 308 | +- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ | |
| 309 | + if (self.delegate && [self.delegate respondsToSelector:@selector(cell:didSelectItemAtItem:)]) { | |
| 310 | + [self.delegate cell:self didSelectItemAtItem:indexPath.item]; | |
| 311 | + } | |
| 344 | 312 | } |
| 345 | 313 | |
| 346 | 314 | @end | ... | ... |
CNLiveMineModule/Classes/View/CNLiveMineHeaderView.m
| ... | ... | @@ -287,23 +287,19 @@ static const NSInteger margin = 20; |
| 287 | 287 | - (void)headerTapDidClicked:(UITapGestureRecognizer *)tap{ |
| 288 | 288 | if (self.delegate && [self.delegate respondsToSelector:@selector(headerView:pushToController:)]) { |
| 289 | 289 | [self.delegate headerView:self pushToController:CNLiveMineHeaderViewTypeUerInfo]; |
| 290 | - | |
| 291 | 290 | } |
| 292 | - | |
| 293 | 291 | } |
| 292 | + | |
| 294 | 293 | - (void)nameTapDidClicked:(UITapGestureRecognizer *)tap{ |
| 295 | 294 | if (self.delegate && [self.delegate respondsToSelector:@selector(headerView:pushToController:)]) { |
| 296 | 295 | [self.delegate headerView:self pushToController:CNLiveMineHeaderViewTypeCode]; |
| 297 | - | |
| 298 | 296 | } |
| 299 | - | |
| 300 | 297 | } |
| 301 | 298 | |
| 302 | 299 | - (void)setInteractionEnabled:(BOOL)interactionEnabled{ |
| 303 | 300 | _interactionEnabled = interactionEnabled; |
| 304 | 301 | _sign.userInteractionEnabled = interactionEnabled; |
| 305 | 302 | _witness.userInteractionEnabled = interactionEnabled; |
| 306 | - | |
| 307 | 303 | } |
| 308 | 304 | |
| 309 | 305 | - (void)signDidClicked:(UIButton *)btn{ | ... | ... |