// // RechargeWayView.m // BuguLive // // Created by 王珂 on 17/3/13. // Copyright © 2017年 xfg. All rights reserved. // #import "RechargeWayView.h" @implementation RechargeWayView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { UICollectionViewFlowLayout * flow = [[UICollectionViewFlowLayout alloc] init] ; CGFloat itemW = (self.width-40)/3.0; CGFloat itemH = 45; //设置cell的大小 flow.itemSize = CGSizeMake(itemW, itemH) ; flow.minimumLineSpacing = 10; flow.minimumInteritemSpacing = 10; flow.sectionInset = UIEdgeInsetsMake(15, 10, 15, 10) ; flow.scrollDirection = 1; _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.width, 75) collectionViewLayout:flow]; _collectionView.delegate = self; _collectionView.dataSource = self; _collectionView.backgroundColor = [UIColor clearColor]; // _collectionView.pagingEnabled = YES; _collectionView.showsHorizontalScrollIndicator = NO; [_collectionView registerNib:[UINib nibWithNibName:@"RechargeWayCell" bundle:nil] forCellWithReuseIdentifier:@"RechargeWayCell"]; [self addSubview:_collectionView]; } return self; } - (void)setRechargeWayArr:(NSArray *)rechargeWayArr { _rechargeWayArr = rechargeWayArr; for (PayTypeModel * model in _rechargeWayArr) { NSString * string; if (model.name.length>0) { string = model.name; } else { if ([model.class_name isEqual:@"Aliapp"]) { string = ASLocalizedString(@"支付宝"); } else if ([model.class_name isEqual:@"Iappay"]) { string = ASLocalizedString(@"苹果内购"); } else if ([model.class_name isEqual:@"WxApp"]) { string = ASLocalizedString(@"微信支付"); } } model.name = string; } NSInteger count = rechargeWayArr.count; if (count>3) { self.selectIndex = 0; _collectionView.hidden = NO; //[self addSubview:_collectionView]; } else { _collectionView.hidden = YES; [_collectionView removeFromSuperview]; while (self.subviews.count3 ? (self.width-10*(count+1))/count:(self.width-40)/3; CGFloat height = 25; for (NSInteger i=0; i0) { string = model.name; } else { if ([model.class_name isEqual:@"Aliapp"]) { string = ASLocalizedString(@"支付宝"); } else if ([model.class_name isEqual:@"Iappay"]) { string = ASLocalizedString(@"苹果内购"); } else if ([model.class_name isEqual:@"WxApp"]) { string = ASLocalizedString(@"微信支付"); } } if (i3) { //self.collectionView.contentOffset = CGPointMake(self.width*(selectIndex/3), 0); [self.collectionView reloadData]; } else { if (self.subviews.count>_selectIndex) { for (UIButton * button in self.subviews) { button.backgroundColor = kWhiteColor; [button setTitleColor:kAppGrayColor1 forState:UIControlStateNormal]; } _selectIndex = selectIndex; UIButton * selectButton = self.subviews[_selectIndex]; selectButton.backgroundColor = kAppGrayColor1; [selectButton setTitleColor:kWhiteColor forState:UIControlStateNormal]; } } } - (void)choseWayBtn:(UIButton *) button { for (int i=0; i