// // EditSelectContactViewController.m // LekangGuard // // Created by ecell on 2022/12/8. // #import "EditSelectContactViewController.h" #import "SelectContactCollectionViewCell.h" @interface EditSelectContactViewController () @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, assign) WSLWaterFlowLayoutStyle flowLayoutStyle; /// 关系Field @property (nonatomic ,weak) UITextField *contactField; /// 昵称Arr @property (nonatomic ,strong) NSArray *nameArr; /// 头像Arr @property (nonatomic ,strong) NSArray *imgArr; /// 关系ID @property (nonatomic ,assign) NSInteger relationshipId; /// 关系 @property (nonatomic ,strong) NSString *relationship; @end @implementation EditSelectContactViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.zx_navTitle = GJText(@"选择关系"); [self zx_setRightBtnWithText:GJText(@"保存") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { // self.isSelectMsg(self.relationshipId, self.relationship.length <= 0 ? self.nameArr[self.relationshipId-1] : self.relationship); if (self.relationship.length <= 0) { [UICommon MessageErrorText:@"请选择关系"]; return; } if (self.contactField.text.length <= 0) { [UICommon MessageErrorText:@"关系名称不能为空"]; return; } self.isSelectMsg(self.relationshipId, self.contactField.text); [self.navigationController popViewControllerAnimated:YES]; }]; self.imgArr = [UICommon getUnclickRelationshipImageArr:APIManager.sharedManager.deviceModel.deviceType]; self.nameArr = [UICommon getRelationshipNameArr:APIManager.sharedManager.deviceModel.deviceType]; UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:RGB(245, 245, 245) cornerRadius:5 borderWidth:0 borderColor:KKClearColor]; [self.view addSubview:bgView]; [bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view).inset(15); make.top.equalTo(self.view).offset(iPhoneX_NavHeight+Adapted(20)); make.height.mas_equalTo(Adapted(50)); }]; UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(13) textColor:KKTextBlackColor text:GJText(@"与我的关系") Radius:0]; CGFloat width = [(NSString *)titleLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 18) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FontADA_(13)} context:nil].size.width; [bgView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(bgView).offset(10); make.centerY.equalTo(bgView); make.width.mas_equalTo(width); }]; UITextField *textfield = [UICommon ui_textField:CGRectZero textColor:KKTextBlackColor backColor:KKClearColor font:FontADA_(13) maxTextNum:20 placeholderColor:KKGrey143 placeholder:GJText(@"请输入关系") toMaxNum:^(UITextField *textField) { } change:^(UITextField *textField) { }]; textfield.textAlignment = NSTextAlignmentRight; self.contactField = textfield; [bgView addSubview:textfield]; [textfield mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(titleLabel.mas_right).offset(7); make.right.equalTo(bgView).inset(10); make.centerY.equalTo(bgView); make.height.mas_equalTo(Adapted(44)); }]; UILabel *titleLabel1 = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(13) textColor:KKTextBlackColor text:GJText(@"选择头像") Radius:0]; [self.view addSubview:titleLabel1]; [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view).offset(15); make.top.equalTo(bgView.mas_bottom).offset(Adapted(20)); }]; WSLWaterFlowLayout *FlowLayout = [[WSLWaterFlowLayout alloc] init]; FlowLayout.delegate = self; FlowLayout.flowLayoutStyle = self.flowLayoutStyle; _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:FlowLayout]; _collectionView.dataSource = self; _collectionView.delegate = self; _collectionView.showsVerticalScrollIndicator = NO; _collectionView.alwaysBounceVertical = YES; _collectionView.allowsMultipleSelection = NO; _collectionView.scrollEnabled = NO; _collectionView.backgroundColor = KKClearColor; if (@available(iOS 11.0, *)) _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; [_collectionView registerClass:SelectContactCollectionViewCell.class forCellWithReuseIdentifier:NSStringFromClass(SelectContactCollectionViewCell.class)]; [self.view addSubview:_collectionView]; [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); make.top.equalTo(titleLabel1.mas_bottom).offset(0); make.bottom.equalTo(self.view.mas_bottom); }]; kWeakSelf(self) AfterDispatch(0.2, ^{ NSIndexPath *indexPaths = [NSIndexPath indexPathForRow:self.relationImageId-1 inSection:0]; [weakself collectionView:weakself.collectionView didSelectItemAtIndexPath:indexPaths]; }); } #pragma mark - WSLWaterFlowLayoutDelegate //返回每个item大小 - (CGSize)waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake((SCREEN_WIDTH-75)/4, (SCREEN_WIDTH-75)/4+Adapted(25)); } /** 头视图Size */ -(CGSize )waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout sizeForHeaderViewInSection:(NSInteger)section { return CGSizeMake(SCREEN_WIDTH, 0.1); } /** 列数*/ -(CGFloat)columnCountInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout { return 4; } /** 列间距*/ -(CGFloat)columnMarginInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout { return 15; } /** 行间距*/ -(CGFloat)rowMarginInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout { return 10; } /** 边缘之间的间距*/ -(UIEdgeInsets)edgeInsetInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout { return UIEdgeInsetsMake(0, 15, 10, 15); } #pragma mark - UICollectionView数据源 //组个数 - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } //组内成员个数 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.imgArr.count; } //设置元素内容 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { SelectContactCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(SelectContactCollectionViewCell.class) forIndexPath:indexPath]; cell.tag = indexPath.item+1; cell.deviceType = APIManager.sharedManager.deviceModel.deviceType; cell.iconImgName = self.imgArr[indexPath.row]; cell.nameStr = self.nameArr[indexPath.row]; return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone]; self.contactField.text = [UICommon getRelationshipNameWithCodeID:indexPath.item+1 deviceType:APIManager.sharedManager.deviceModel.deviceType]; self.relationship = self.contactField.text; self.relationshipId = indexPath.item+1; } /* #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