You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
5.4 KiB
161 lines
5.4 KiB
// |
|
// 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 = 15.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.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.placeholder = @"请输入地址名称"; |
|
UICollectionViewFlowLayout *FL = [[UICollectionViewFlowLayout alloc] init]; |
|
FL.minimumInteritemSpacing= 5; |
|
self.myCollection.collectionViewLayout = FL; |
|
if(self.infoRail){ |
|
self.addressTextField.text = self.infoRail.name; |
|
} |
|
[self zx_setRightBtnWithText:@"保存" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { |
|
[self saveBtnAction]; |
|
}]; |
|
[self.topView mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view); |
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight+15); |
|
make.height.mas_equalTo(49); |
|
}]; |
|
} |
|
|
|
- (void)saveBtnAction |
|
{ |
|
[self.addressTextField resignFirstResponder]; |
|
if(self.addressTextField.text.length == 0){ |
|
[SVProgressHUD showErrorWithStatus:@"请设置地址名称"]; |
|
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){textSize.width+4+4+40, 30}; |
|
} |
|
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ |
|
return UIEdgeInsetsMake(18, 0, 0, 0); |
|
} |
|
//设置水平间距 (同一行的cell的左右间距) |
|
|
|
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { |
|
|
|
return 10; |
|
} |
|
//垂直间距 (同一列cell上下间距) |
|
|
|
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { |
|
|
|
return 20; |
|
} |
|
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ |
|
NSString * title = self.myDataSource[indexPath.item]; |
|
self.addressTextField.text = title; |
|
} |
|
|
|
|
|
|
|
//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]; |
|
}else{ |
|
[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
|
|
|