(void)configCollectionView {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
CGFloat margin = 4;
CGFloat itemWH = (self.view.width - 2 * margin - 4) / 4 - margin;
layout.itemSize = CGSizeMake(itemWH, itemWH);
layout.minimumInteritemSpacing = margin;
layout.minimumLineSpacing = margin;
CGFloat top = margin + 44;
if (iOS7Later) top += 20;
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(margin, top, self.view.width - 2 * margin, self.view.height - 50 - top) collectionViewLayout:layout];
self.collectionView.backgroundColor = [UIColor whiteColor];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
self.collectionView.alwaysBounceHorizontal = NO;
if (iOS7Later) self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 2);
self.collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -2);
self.collectionView.contentSize = CGSizeMake(self.view.width, ((self.model.count + 3) / 4) * self.view.width);
[self.view addSubview:self.collectionView];
[self.collectionView registerNib:[UINib nibWithNibName:@"TZAssetCell" bundle:nil] forCellWithReuseIdentifier:@"TZAssetCell"];
}
(void)configBottomToolBar {
UIView *bottomToolBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.height - 50, self.view.width, 50)];
CGFloat rgb = 253 / 255.0;
bottomToolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0];
_previewButton = [UIButton buttonWithType:UIButtonTypeCustom];
_previewButton.frame = CGRectMake(10, 3, 44, 44);
[_previewButton addTarget:self action:@selector(previewButtonClick) forControlEvents:UIControlEventTouchUpInside];
_previewButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_previewButton setTitle:@"预览" forState:UIControlStateNormal];
[_previewButton setTitle:@"预览" forState:UIControlStateDisabled];
[_previewButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_previewButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
_previewButton.enabled = NO;
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
if (imagePickerVc.allowPickingOriginalPhoto) {
_originalPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
_originalPhotoButton.frame = CGRectMake(50, self.view.height - 50, 130, 50);
_originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, -8, 0, 0);
_originalPhotoButton.contentEdgeInsets = UIEdgeInsetsMake(0, -45, 0, 0);
[_originalPhotoButton addTarget:self action:@selector(originalPhotoButtonClick) forControlEvents:UIControlEventTouchUpInside];
_originalPhotoButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_originalPhotoButton setTitle:@"原图" forState:UIControlStateNormal];
[_originalPhotoButton setTitle:@"原图" forState:UIControlStateSelected];
[_originalPhotoButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
[_originalPhotoButton setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
[_originalPhotoButton setImage:[UIImage imageNamed:@"photo_original_def"] forState:UIControlStateNormal];
[_originalPhotoButton setImage:[UIImage imageNamed:@"photo_original_sel"] forState:UIControlStateSelected];
_originalPhotoButton.enabled = _selectedPhotoArr.count > 0;
_originalPhotoLable = [[UILabel alloc] init];
_originalPhotoLable.frame = CGRectMake(70, 0, 60, 50);
_originalPhotoLable.textAlignment = NSTextAlignmentLeft;
_originalPhotoLable.font = [UIFont systemFontOfSize:16];
_originalPhotoLable.textColor = [UIColor blackColor];
if (_isSelectOriginalPhoto) [self getSelectedPhotoBytes];
}
_okButton = [UIButton buttonWithType:UIButtonTypeCustom];
_okButton.frame = CGRectMake(self.view.width - 44 - 12, 3, 44, 44);
_okButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_okButton addTarget:self action:@selector(okButtonClick) forControlEvents:UIControlEventTouchUpInside];
[_okButton setTitle:@"确定" forState:UIControlStateNormal];
[_okButton setTitle:@"确定" forState:UIControlStateDisabled];
[_okButton setTitleColor:kOKButtonTitleColorNormal forState:UIControlStateNormal];
[_okButton setTitleColor:kOKButtonTitleColorDisabled forState:UIControlStateDisabled];
_okButton.enabled = NO;
_numberImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo_number_icon"]];
_numberImageView.frame = CGRectMake(self.view.width - 56 - 24, 12, 26, 26);
_numberImageView.hidden = _selectedPhotoArr.count <= 0;
_numberImageView.backgroundColor = [UIColor clearColor];
_numberLable = [[UILabel alloc] init];
_numberLable.frame = _numberImageView.frame;
_numberLable.font = [UIFont systemFontOfSize:16];
_numberLable.textColor = [UIColor whiteColor];
_numberLable.textAlignment = NSTextAlignmentCenter;
_numberLable.text = [NSString stringWithFormat:@"%zd",_selectedPhotoArr.count];
_numberLable.hidden = _selectedPhotoArr.count <= 0;
_numberLable.backgroundColor = [UIColor clearColor];
UIView *divide = [[UIView alloc] init];
CGFloat rgb2 = 222 / 255.0;
divide.backgroundColor = [UIColor colorWithRed:rgb2 green:rgb2 blue:rgb2 alpha:1.0];
divide.frame = CGRectMake(0, 0, self.view.width, 1);
[bottomToolBar addSubview:divide];
[bottomToolBar addSubview:_previewButton];
[bottomToolBar addSubview:_okButton];
[bottomToolBar addSubview:_numberImageView];
[bottomToolBar addSubview:_numberLable];
[self.view addSubview:bottomToolBar];
[self.view addSubview:_originalPhotoButton];
[_originalPhotoButton addSubview:_originalPhotoLable];
}