|
|
|
//
|
|
|
|
// RailADNameChooseVC.m
|
|
|
|
// tongxin
|
|
|
|
//
|
|
|
|
// Created by WeiChaoZheng on 2018/11/7.
|
|
|
|
// Copyright © 2018年 xTT. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "RailADNameChooseVC.h"
|
|
|
|
|
|
|
|
@implementation RailADNameChooseCollectionCell
|
|
|
|
-(void)awakeFromNib{
|
|
|
|
[super awakeFromNib];
|
|
|
|
|
|
|
|
self.itemTitleLabel.layer.borderColor = RGB(229, 229, 229).CGColor;
|
|
|
|
_itemTitleLabel.layer.borderWidth = 1;
|
|
|
|
self.itemTitleLabel.textAlignment = 1;
|
|
|
|
|
|
|
|
self.itemTitleLabel.layer.cornerRadius = 18.f;
|
|
|
|
self.itemTitleLabel.layer.masksToBounds = YES;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface RailADNameChooseVC ()<UICollectionViewDelegateFlowLayout,
|
|
|
|
UICollectionViewDelegate,
|
|
|
|
UICollectionViewDataSource,
|
|
|
|
UITextFieldDelegate>
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RailADNameChooseVC
|
|
|
|
@synthesize myDataSource = _myDataSource;
|
|
|
|
-(NSMutableArray *)myDataSource{
|
|
|
|
if(!_myDataSource){
|
|
|
|
_myDataSource = [NSMutableArray arrayWithArray:@[@"学校",@"家",@"朋友",@"公园",@"超市",@"广场",]];
|
|
|
|
}
|
|
|
|
return _myDataSource;
|
|
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
self.zx_navTitle = @"地址名称";
|
|
|
|
[self zx_setRightBtnWithText:@"保存" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
|
|
|
|
[self saveBtnAction];
|
|
|
|
}];
|
|
|
|
self.zx_navRightBtn.alpha = 0.5;
|
|
|
|
self.zx_navRightBtn.enabled = NO;
|
|
|
|
self.zx_backBtnImageName = @"";
|
|
|
|
[self zx_setLeftBtnWithText:@"取消" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
|
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
|
|
}];
|
|
|
|
[self.zx_navRightBtn setTitleColor:mainColor forState:0];
|
|
|
|
self.view.backgroundColor = tabViewBG;
|
|
|
|
self.myCollection.backgroundColor = [UIColor whiteColor];
|
|
|
|
self.myCollection.delegate = self;
|
|
|
|
self.myCollection.dataSource = self;
|
|
|
|
[self.closeBtn setHidden:YES];
|
|
|
|
self.addressTextField.delegate = self;
|
|
|
|
self.addressTextField.font = Font_(16);
|
|
|
|
self.addressTextField.placeholder = @"请输入地址名称";
|
|
|
|
UICollectionViewFlowLayout *FL = [[UICollectionViewFlowLayout alloc] init];
|
|
|
|
FL.minimumInteritemSpacing = 16;
|
|
|
|
self.myCollection.collectionViewLayout = FL;
|
|
|
|
if(self.infoRail){
|
|
|
|
self.addressTextField.text = self.infoRail.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)saveBtnAction
|
|
|
|
{
|
|
|
|
[self.addressTextField resignFirstResponder];
|
|
|
|
if(self.addressTextField.text.length == 0){
|
|
|
|
[UICommon MessageErrorText:@"请设置地址名称"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.infoRail.name = self.addressTextField.text;
|
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
清除 输入框的按钮
|
|
|
|
*/
|
|
|
|
- (IBAction)closeBtnAction:(id)sender {
|
|
|
|
self.addressTextField.text = @"";
|
|
|
|
[sender setHidden:YES];
|
|
|
|
}
|
|
|
|
#pragma collectionView
|
|
|
|
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
|
|
|
{
|
|
|
|
// 功能列表
|
|
|
|
return self.myDataSource.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
|
|
|
|
// 功能的 collection
|
|
|
|
RailADNameChooseCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RailADNameChooseCollectionCell"
|
|
|
|
forIndexPath:indexPath];
|
|
|
|
cell.itemTitleLabel.text = self.myDataSource[indexPath.item];
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
NSString *title = self.myDataSource[indexPath.item];
|
|
|
|
CGSize textSize = [title sizeWithAttributes:@{NSFontAttributeName:DefineFontSize}];
|
|
|
|
|
|
|
|
//根据文字计算 宽度
|
|
|
|
return (CGSize){Adapted(68), 36};
|
|
|
|
}
|
|
|
|
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
|
|
|
|
return UIEdgeInsetsMake(16, 16, 0, 16);
|
|
|
|
}
|
|
|
|
//设置水平间距 (同一行的cell的左右间距)
|
|
|
|
|
|
|
|
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//垂直间距 (同一列cell上下间距)
|
|
|
|
|
|
|
|
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
|
|
|
|
|
|
|
|
return 13;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
NSString * title = self.myDataSource[indexPath.item];
|
|
|
|
self.addressTextField.text = title;
|
|
|
|
self.zx_navRightBtn.alpha = 1;
|
|
|
|
self.zx_navRightBtn.enabled = YES;
|
|
|
|
[self.closeBtn setHidden:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//MARK: -------- UITextField -------
|
|
|
|
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
|
|
|
|
// 最终的结果
|
|
|
|
NSString *str = textField.text;
|
|
|
|
NSString *resultStr = [str stringByReplacingCharactersInRange:range withString:string];
|
|
|
|
if(resultStr.length == 0){
|
|
|
|
|
|
|
|
[self.closeBtn setHidden:YES];
|
|
|
|
self.zx_navRightBtn.alpha = 0.5;
|
|
|
|
self.zx_navRightBtn.enabled = NO;
|
|
|
|
}else{
|
|
|
|
self.zx_navRightBtn.alpha = 1;
|
|
|
|
self.zx_navRightBtn.enabled = YES;
|
|
|
|
[self.closeBtn setHidden:NO];
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
// Dispose of any resources that can be recreated.
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
#pragma mark - Navigation
|
|
|
|
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
|
// Get the new view controller using [segue destinationViewController].
|
|
|
|
// Pass the selected object to the new view controller.
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
@end
|