YOUPAILZChatRoomInfoEditWindow.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // YOUPAILZChatRoomInfoEditWindow.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/10/29.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZChatRoomInfoEditWindow.h"
  9. #import "YOUPAILZTextView.h"
  10. #import "IQKeyboardManager.h"
  11. @interface YOUPAILZChatRoomInfoEditWindow ()
  12. @property (nonatomic,weak)UITextField *youpaipnameTF;
  13. @property (nonatomic,strong)UILabel *youpaipnameLengthL;
  14. @property (nonatomic,weak)YOUPAILZTextView *youpaipnoticeTextView;
  15. @property (nonatomic,weak)UIButton *youpaipsaveBtn;
  16. @end
  17. @implementation YOUPAILZChatRoomInfoEditWindow
  18. - (void)viewWillAppear:(BOOL)animated {
  19. [super viewWillAppear:animated];
  20. [[IQKeyboardManager sharedManager] setEnable:YES];
  21. }
  22. - (void)viewWillDisappear:(BOOL)animated {
  23. [super viewWillDisappear:animated];
  24. [[IQKeyboardManager sharedManager] setEnable:NO];
  25. }
  26. - (void)dealloc{
  27. [[NSNotificationCenter defaultCenter] removeObserver:self];
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. self.baseView.hidden = YES;
  32. [IQKeyboardManager sharedManager].enableAutoToolbar = NO; // 控制是否显示键盘上的工具条
  33. [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = NavBarHeight; //
  34. [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
  35. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifhideKeyboard) name:UIKeyboardWillHideNotification object:nil];
  36. [self youpaifinitUI];
  37. }
  38. - (void)youpaifinitUI{
  39. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 506.0f + SafeHeight)];
  40. bgV.backgroundColor = HexColorFromRGB(0x2A2935);
  41. [self.view addSubview:bgV];
  42. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.left.right.bottom.offset(0.0f);
  44. make.height.offset(506.0f + SafeHeight);
  45. }];
  46. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)];
  47. UIView *navV = [[UIView alloc] init];
  48. [bgV addSubview:navV];
  49. [navV mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.right.top.offset(0.0f);
  51. make.height.offset(49.0f);
  52. }];
  53. UIButton *youpaipcloseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  54. [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_nav_return_white"] forState:UIControlStateNormal];
  55. [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_nav_return_white"] forState:UIControlStateHighlighted];
  56. [youpaipcloseBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside];
  57. [navV addSubview:youpaipcloseBtn];
  58. [youpaipcloseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.offset(4.0f);
  60. make.centerY.equalTo(navV);
  61. make.size.mas_offset(CGSizeMake(44.0f, 44.0f));
  62. }];
  63. UILabel *titleL = [[UILabel alloc] init];
  64. titleL.text = @"房间资料";
  65. titleL.textColor = [UIColor whiteColor];
  66. titleL.font = LCBoldFont(17.0f);
  67. [navV addSubview:titleL];
  68. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.center.equalTo(navV);
  70. }];
  71. UILabel *nameL = [[UILabel alloc] init];
  72. nameL.font = LCFont(12.0f);
  73. nameL.textColor = HexColorFromRGB(0x9F9DA5);
  74. nameL.text = @"房间名称";
  75. [bgV addSubview:nameL];
  76. [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.left.offset(14.0f);
  78. make.top.equalTo(navV.mas_bottom).offset(10.0f);
  79. make.height.offset(17.0f);
  80. }];
  81. UITextField *youpaipnameTF = [[UITextField alloc] init];
  82. [youpaipnameTF addTarget:self action:@selector(textLengthChange:) forControlEvents:UIControlEventEditingChanged];
  83. youpaipnameTF.text = self.youpaipchatroomModel.youpaiproom_title;
  84. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12.0f, 48.0f)];
  85. youpaipnameTF.leftView = leftView;
  86. youpaipnameTF.leftViewMode = UITextFieldViewModeAlways;
  87. UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 48.0f)];
  88. UILabel *youpaipnameLengthL = [[UILabel alloc] init];
  89. youpaipnameLengthL.font = LCFont(14.0f);
  90. youpaipnameLengthL.textColor = HexColorFromRGB(0x6C6B70);
  91. youpaipnameLengthL.text = [NSString stringWithFormat:@"%@/15",@(self.youpaipchatroomModel.youpaiproom_title.length)];
  92. if (self.youpaipchatroomModel.youpaiproom_title.length >= 15) {
  93. youpaipnameLengthL.textColor = HexColorFromRGB(0xF4003F);
  94. }else{
  95. youpaipnameLengthL.textColor = HexColorFromRGB(0x6C6B70);
  96. }
  97. youpaipnameLengthL.textAlignment = NSTextAlignmentRight;
  98. [rightView addSubview:youpaipnameLengthL];
  99. self.youpaipnameLengthL = youpaipnameLengthL;
  100. [youpaipnameLengthL mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.left.offset(12.0f);
  102. make.right.offset(-12.0f);
  103. make.top.bottom.offset(0.0f);
  104. }];
  105. youpaipnameTF.rightView = rightView;
  106. youpaipnameTF.rightViewMode = UITextFieldViewModeAlways;
  107. youpaipnameTF.backgroundColor = HexColorFromRGB(0x4F4B5B);
  108. youpaipnameTF.layer.cornerRadius = 5.0f;
  109. youpaipnameTF.clipsToBounds = YES;
  110. NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc]initWithString:@"请输入房间名称"];
  111. [attrStr addAttribute:NSFontAttributeName value:LCFont(14) range:NSMakeRange(0, attrStr.length)];
  112. [attrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x908E96) range:NSMakeRange(0, attrStr.length)];
  113. youpaipnameTF.attributedPlaceholder = attrStr;
  114. youpaipnameTF.textColor = [UIColor whiteColor];
  115. youpaipnameTF.font = LCFont14;
  116. youpaipnameTF.tintColor = ZYPinkColor;
  117. [bgV addSubview:youpaipnameTF];
  118. self.youpaipnameTF = youpaipnameTF;
  119. [youpaipnameTF mas_makeConstraints:^(MASConstraintMaker *make) {
  120. make.left.offset(14.0f);
  121. make.top.equalTo(nameL.mas_bottom).offset(10.0f);
  122. make.height.offset(48.0f);
  123. make.width.offset(KScreenWidth - 28.0f);
  124. }];
  125. UILabel *noticeL = [[UILabel alloc] init];
  126. noticeL.font = LCFont(12.0f);
  127. noticeL.textColor = HexColorFromRGB(0x9F9DA5);
  128. noticeL.text = @"房间公告";
  129. [bgV addSubview:noticeL];
  130. [noticeL mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.left.offset(14.0f);
  132. make.top.equalTo(youpaipnameTF.mas_bottom).offset(24.0f);
  133. make.height.offset(17.0f);
  134. }];
  135. YOUPAILZTextView *youpaipnoticeTextView = [[YOUPAILZTextView alloc] initWithMaxCount:200.0f];
  136. youpaipnoticeTextView.youpaiptextViewPadding = UIEdgeInsetsMake(15.0f, 12.0f, 16.0f, 12.0f);
  137. youpaipnoticeTextView.youpaiptextLengthDefaultColor = HexColorFromRGB(0x6C6B70);
  138. youpaipnoticeTextView.youpaiptextLengthHigtColor = ZYPinkColor;
  139. youpaipnoticeTextView.youpaiptextLengthFont = LCFont(14.0f);
  140. youpaipnoticeTextView.youpaiptextLengthRight = 12.0f;
  141. youpaipnoticeTextView.youpaiptextLengthBottom = 18.0f;
  142. youpaipnoticeTextView.youpaiptextView.placeholderFont = LCFont(14.0f);
  143. youpaipnoticeTextView.youpaiptextView.placeholderTextColor = HexColorFromRGB(0x908E96);
  144. youpaipnoticeTextView.youpaiptextView.placeholderText = @"请输入房间公告";
  145. youpaipnoticeTextView.youpaiptextView.textColor = [UIColor whiteColor];
  146. youpaipnoticeTextView.youpaiptextView.font = LCFont(14.0f);
  147. youpaipnoticeTextView.youpaiptextView.text = self.youpaipchatroomModel.youpaiptalk_notice;
  148. youpaipnoticeTextView.backgroundColor = HexColorFromRGB(0x4F4B5B);
  149. youpaipnoticeTextView.layer.cornerRadius = 5.0f;
  150. youpaipnoticeTextView.clipsToBounds = YES;
  151. youpaipnoticeTextView.tintColor = ZYPinkColor;
  152. [bgV addSubview:youpaipnoticeTextView];
  153. self.youpaipnoticeTextView = youpaipnoticeTextView;
  154. [youpaipnoticeTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  155. make.left.offset(14.0f);
  156. make.top.equalTo(noticeL.mas_bottom).offset(10.0f);
  157. make.size.mas_offset(CGSizeMake(KScreenWidth - 28.0f, 220.0f));
  158. }];
  159. UIButton *youpaipsaveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  160. [youpaipsaveBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] ByGradientType:GradientLeftToRight] forState:UIControlStateSelected];
  161. [youpaipsaveBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  162. [youpaipsaveBtn setTitle:@"保存资料" forState:UIControlStateNormal];
  163. [youpaipsaveBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal];
  164. [youpaipsaveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  165. youpaipsaveBtn.titleLabel.font = LCFont(16.0f);
  166. youpaipsaveBtn.layer.cornerRadius = 24.0f;
  167. youpaipsaveBtn.clipsToBounds = YES;
  168. [youpaipsaveBtn addTarget:self action:@selector(youpaifsaveBtnClick) forControlEvents:UIControlEventTouchUpInside];
  169. [bgV addSubview:youpaipsaveBtn];
  170. self.youpaipsaveBtn = youpaipsaveBtn;
  171. [youpaipsaveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  172. make.left.offset(40.0f);
  173. make.top.equalTo(youpaipnoticeTextView.mas_bottom).offset(20.0f);
  174. make.size.mas_offset(CGSizeMake(KScreenWidth - 80.0f, 48.0f));
  175. }];
  176. }
  177. - (void)textLengthChange:(UITextField *)sender{
  178. NSString * temp = sender.text;
  179. if (temp.length >= 15) {
  180. self.youpaipnameLengthL.textColor = HexColorFromRGB(0xF4003F);;
  181. sender.text = [sender.text substringToIndex:15];
  182. }else{
  183. self.youpaipnameLengthL.textColor = HexColorFromRGB(0x6C6B70);
  184. }
  185. self.youpaipnameLengthL.text = [NSString stringWithFormat:@"%@/%@",@(sender.text.length),@(15)];
  186. }
  187. - (void)youpaifhideKeyboard{
  188. dispatch_async(dispatch_get_main_queue(), ^{
  189. [self.view endEditing:YES];
  190. });
  191. // if ([self.youpaipnameTF.text isEqual:self.youpaipchatroomModel.room_title] && [self.youpaipnoticeTextView.textView.text isEqual:self.youpaipchatroomModel.talk_notice]) {
  192. // return;
  193. // }
  194. if (self.youpaipnameTF.text.length != 0) {
  195. self.youpaipsaveBtn.selected = YES;
  196. self.youpaipsaveBtn.userInteractionEnabled = YES;
  197. }else{
  198. self.youpaipsaveBtn.selected = NO;
  199. self.youpaipsaveBtn.userInteractionEnabled = NO;
  200. }
  201. }
  202. - (void)youpaifcloseBtnClick{
  203. [self dismissViewControllerAnimated:YES completion:^{}];
  204. }
  205. - (void)youpaifsaveBtnClick{
  206. @weakify(self);
  207. [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) {
  208. @strongify(self);
  209. NSDictionary* dict = (NSDictionary*)responseObject;
  210. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  211. if (code==0) {//成功
  212. [ZCHUDHelper showTitle:@"房间资料已修改"];
  213. [self dismissViewControllerAnimated:YES completion:^{}];
  214. }
  215. } failure:^(NSError *error) {
  216. }];
  217. }
  218. @end