// // YOUPAILZChatRoomInfoEditWindow.m // VQU // // Created by CY on 2021/10/29. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZChatRoomInfoEditWindow.h" #import "YOUPAILZTextView.h" #import "IQKeyboardManager.h" @interface YOUPAILZChatRoomInfoEditWindow () @property (nonatomic,weak)UITextField *youpaipnameTF; @property (nonatomic,strong)UILabel *youpaipnameLengthL; @property (nonatomic,weak)YOUPAILZTextView *youpaipnoticeTextView; @property (nonatomic,weak)UIButton *youpaipsaveBtn; @end @implementation YOUPAILZChatRoomInfoEditWindow - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[IQKeyboardManager sharedManager] setEnable:YES]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[IQKeyboardManager sharedManager] setEnable:NO]; } - (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)viewDidLoad { [super viewDidLoad]; self.baseView.hidden = YES; [IQKeyboardManager sharedManager].enableAutoToolbar = NO; // 控制是否显示键盘上的工具条 [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = NavBarHeight; // [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifhideKeyboard) name:UIKeyboardWillHideNotification object:nil]; [self youpaifinitUI]; } - (void)youpaifinitUI{ UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 506.0f + SafeHeight)]; bgV.backgroundColor = HexColorFromRGB(0x2A2935); [self.view addSubview:bgV]; [bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.offset(0.0f); make.height.offset(506.0f + SafeHeight); }]; [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)]; UIView *navV = [[UIView alloc] init]; [bgV addSubview:navV]; [navV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.offset(0.0f); make.height.offset(49.0f); }]; UIButton *youpaipcloseBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_nav_return_white"] forState:UIControlStateNormal]; [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_nav_return_white"] forState:UIControlStateHighlighted]; [youpaipcloseBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside]; [navV addSubview:youpaipcloseBtn]; [youpaipcloseBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(4.0f); make.centerY.equalTo(navV); make.size.mas_offset(CGSizeMake(44.0f, 44.0f)); }]; UILabel *titleL = [[UILabel alloc] init]; titleL.text = @"房间资料"; titleL.textColor = [UIColor whiteColor]; titleL.font = LCBoldFont(17.0f); [navV addSubview:titleL]; [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(navV); }]; UILabel *nameL = [[UILabel alloc] init]; nameL.font = LCFont(12.0f); nameL.textColor = HexColorFromRGB(0x9F9DA5); nameL.text = @"房间名称"; [bgV addSubview:nameL]; [nameL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.top.equalTo(navV.mas_bottom).offset(10.0f); make.height.offset(17.0f); }]; UITextField *youpaipnameTF = [[UITextField alloc] init]; [youpaipnameTF addTarget:self action:@selector(textLengthChange:) forControlEvents:UIControlEventEditingChanged]; youpaipnameTF.text = self.youpaipchatroomModel.youpaiproom_title; UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12.0f, 48.0f)]; youpaipnameTF.leftView = leftView; youpaipnameTF.leftViewMode = UITextFieldViewModeAlways; UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 48.0f)]; UILabel *youpaipnameLengthL = [[UILabel alloc] init]; youpaipnameLengthL.font = LCFont(14.0f); youpaipnameLengthL.textColor = HexColorFromRGB(0x6C6B70); youpaipnameLengthL.text = [NSString stringWithFormat:@"%@/15",@(self.youpaipchatroomModel.youpaiproom_title.length)]; if (self.youpaipchatroomModel.youpaiproom_title.length >= 15) { youpaipnameLengthL.textColor = HexColorFromRGB(0xF4003F); }else{ youpaipnameLengthL.textColor = HexColorFromRGB(0x6C6B70); } youpaipnameLengthL.textAlignment = NSTextAlignmentRight; [rightView addSubview:youpaipnameLengthL]; self.youpaipnameLengthL = youpaipnameLengthL; [youpaipnameLengthL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(12.0f); make.right.offset(-12.0f); make.top.bottom.offset(0.0f); }]; youpaipnameTF.rightView = rightView; youpaipnameTF.rightViewMode = UITextFieldViewModeAlways; youpaipnameTF.backgroundColor = HexColorFromRGB(0x4F4B5B); youpaipnameTF.layer.cornerRadius = 5.0f; youpaipnameTF.clipsToBounds = YES; NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc]initWithString:@"请输入房间名称"]; [attrStr addAttribute:NSFontAttributeName value:LCFont(14) range:NSMakeRange(0, attrStr.length)]; [attrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x908E96) range:NSMakeRange(0, attrStr.length)]; youpaipnameTF.attributedPlaceholder = attrStr; youpaipnameTF.textColor = [UIColor whiteColor]; youpaipnameTF.font = LCFont14; youpaipnameTF.tintColor = ZYPinkColor; [bgV addSubview:youpaipnameTF]; self.youpaipnameTF = youpaipnameTF; [youpaipnameTF mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.top.equalTo(nameL.mas_bottom).offset(10.0f); make.height.offset(48.0f); make.width.offset(KScreenWidth - 28.0f); }]; UILabel *noticeL = [[UILabel alloc] init]; noticeL.font = LCFont(12.0f); noticeL.textColor = HexColorFromRGB(0x9F9DA5); noticeL.text = @"房间公告"; [bgV addSubview:noticeL]; [noticeL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.top.equalTo(youpaipnameTF.mas_bottom).offset(24.0f); make.height.offset(17.0f); }]; YOUPAILZTextView *youpaipnoticeTextView = [[YOUPAILZTextView alloc] initWithMaxCount:200.0f]; youpaipnoticeTextView.youpaiptextViewPadding = UIEdgeInsetsMake(15.0f, 12.0f, 16.0f, 12.0f); youpaipnoticeTextView.youpaiptextLengthDefaultColor = HexColorFromRGB(0x6C6B70); youpaipnoticeTextView.youpaiptextLengthHigtColor = ZYPinkColor; youpaipnoticeTextView.youpaiptextLengthFont = LCFont(14.0f); youpaipnoticeTextView.youpaiptextLengthRight = 12.0f; youpaipnoticeTextView.youpaiptextLengthBottom = 18.0f; youpaipnoticeTextView.youpaiptextView.placeholderFont = LCFont(14.0f); youpaipnoticeTextView.youpaiptextView.placeholderTextColor = HexColorFromRGB(0x908E96); youpaipnoticeTextView.youpaiptextView.placeholderText = @"请输入房间公告"; youpaipnoticeTextView.youpaiptextView.textColor = [UIColor whiteColor]; youpaipnoticeTextView.youpaiptextView.font = LCFont(14.0f); youpaipnoticeTextView.youpaiptextView.text = self.youpaipchatroomModel.youpaiptalk_notice; youpaipnoticeTextView.backgroundColor = HexColorFromRGB(0x4F4B5B); youpaipnoticeTextView.layer.cornerRadius = 5.0f; youpaipnoticeTextView.clipsToBounds = YES; youpaipnoticeTextView.tintColor = ZYPinkColor; [bgV addSubview:youpaipnoticeTextView]; self.youpaipnoticeTextView = youpaipnoticeTextView; [youpaipnoticeTextView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.top.equalTo(noticeL.mas_bottom).offset(10.0f); make.size.mas_offset(CGSizeMake(KScreenWidth - 28.0f, 220.0f)); }]; UIButton *youpaipsaveBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [youpaipsaveBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] ByGradientType:GradientLeftToRight] forState:UIControlStateSelected]; [youpaipsaveBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal]; [youpaipsaveBtn setTitle:@"保存资料" forState:UIControlStateNormal]; [youpaipsaveBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal]; [youpaipsaveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected]; youpaipsaveBtn.titleLabel.font = LCFont(16.0f); youpaipsaveBtn.layer.cornerRadius = 24.0f; youpaipsaveBtn.clipsToBounds = YES; [youpaipsaveBtn addTarget:self action:@selector(youpaifsaveBtnClick) forControlEvents:UIControlEventTouchUpInside]; [bgV addSubview:youpaipsaveBtn]; self.youpaipsaveBtn = youpaipsaveBtn; [youpaipsaveBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(40.0f); make.top.equalTo(youpaipnoticeTextView.mas_bottom).offset(20.0f); make.size.mas_offset(CGSizeMake(KScreenWidth - 80.0f, 48.0f)); }]; } - (void)textLengthChange:(UITextField *)sender{ NSString * temp = sender.text; if (temp.length >= 15) { self.youpaipnameLengthL.textColor = HexColorFromRGB(0xF4003F);; sender.text = [sender.text substringToIndex:15]; }else{ self.youpaipnameLengthL.textColor = HexColorFromRGB(0x6C6B70); } self.youpaipnameLengthL.text = [NSString stringWithFormat:@"%@/%@",@(sender.text.length),@(15)]; } - (void)youpaifhideKeyboard{ dispatch_async(dispatch_get_main_queue(), ^{ [self.view endEditing:YES]; }); // if ([self.youpaipnameTF.text isEqual:self.youpaipchatroomModel.room_title] && [self.youpaipnoticeTextView.textView.text isEqual:self.youpaipchatroomModel.talk_notice]) { // return; // } if (self.youpaipnameTF.text.length != 0) { self.youpaipsaveBtn.selected = YES; self.youpaipsaveBtn.userInteractionEnabled = YES; }else{ self.youpaipsaveBtn.selected = NO; self.youpaipsaveBtn.userInteractionEnabled = NO; } } - (void)youpaifcloseBtnClick{ [self dismissViewControllerAnimated:YES completion:^{}]; } - (void)youpaifsaveBtnClick{ @weakify(self); [LCHttpHelper requestWithURLString:SetTalkTitleANotice parameters:@{@"room_id":self.youpaipchatroomModel.youpaiproom_id,@"title":self.youpaipnameTF.text,@"notice":self.youpaipnoticeTextView.youpaiptextView.text} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [ZCHUDHelper showTitle:@"房间资料已修改"]; [self dismissViewControllerAnimated:YES completion:^{}]; } } failure:^(NSError *error) { }]; } @end