VoiceLiveTopView.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // PublishLiveTopView.m
  3. // BuguLive
  4. //
  5. // Created by xgh on 2017/8/24.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "VoiceLiveTopView.h"
  9. @implementation VoiceLiveTopView
  10. - (instancetype)initWithFrame:(CGRect)frame
  11. {
  12. self= [super initWithFrame:frame];
  13. if (self) {
  14. [self locationCityJudge];
  15. self.locationBtn = [self setButtomNormalImage:@"pl_publishlive_nolocation" selectedImage:@"pl_publishlive_location" text:ASLocalizedString(@"开启定位")normalcolor:kAppGrayColor4 selectedColor:kWhiteColor frame:CGRectMake(15, 25, 65, kRealValue(45)) sel:@selector(locationBtnAction:)];
  16. self.locationBtn.selected = YES;
  17. self.locationBtn.hidden = YES;
  18. self.isCanLocation = YES;
  19. [self.locationBtn setTitle:[NSString stringWithFormat:@"%@", _locationCityString] forState:UIControlStateSelected];
  20. self.pravicyBtn = [self setButtomNormalImage:@"pl_publishlive_pravicyoff" selectedImage:@"pl_publishlive_pravicyon" text:ASLocalizedString(@"私密")normalcolor:kAppGrayColor4 selectedColor:kWhiteColor frame:CGRectMake(80, 25, kRealValue(60), kRealValue(45)) sel:@selector(pravicyBtnAction:)];
  21. self.pravicyBtn.centerY = self.locationBtn.centerY;
  22. self.pravicyBtn.hidden = YES;
  23. self.passwordBtn = [self setButtomNormalImage:@"pl_publishlive_key_off" selectedImage:@"pl_publishlive_key_on" text:ASLocalizedString(@"密码")normalcolor:kAppGrayColor4 selectedColor:kWhiteColor frame:CGRectMake(self.pravicyBtn.left, 25, kRealValue(60), kRealValue(45)) sel:@selector(passwordBtnAction:)];
  24. self.passwordBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  25. self.passwordBtn.centerY = self.locationBtn.centerY;
  26. self.passwordBtn.hidden = YES;
  27. self.shopBtn = [self setButtomNormalImage:@"pl_publishlive_shop_off" selectedImage:@"pl_publishlive_shop_on" text:ASLocalizedString(@"购物")normalcolor:kAppGrayColor4 selectedColor:kWhiteColor frame:CGRectMake(self.passwordBtn.right, 25, kRealValue(80), kRealValue(45)) sel:@selector(shopBtnAction:)];
  28. self.shopBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  29. self.shopBtn.centerY = self.locationBtn.centerY;
  30. self.shopBtn.hidden = YES;
  31. // if ([[GlobalVariables sharedInstance].appModel.is_open_shop isEqualToString:@"1"]) {
  32. self.shopBtn.hidden = YES;
  33. // }
  34. self.classifyBtn = [self setButtomNormalImage:@"pl_publishlive_classify" selectedImage:@"pl_publishlive_classify" text:ASLocalizedString(@"直播分类:请选择")normalcolor:kWhiteColor selectedColor:kWhiteColor frame:CGRectMake(self.locationBtn.left, self.locationBtn.bottom + 36, 200, 20) sel:@selector(classifyBtnAction:)];
  35. self.classifyBtn.imagePosition = QMUIButtonImagePositionRight;
  36. self.classifyBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  37. self.classifyBtn.hidden = YES;
  38. self.closeBtn = [self setButtomNormalImage:@"ac_auction_back" selectedImage:@"ac_auction_back" text:@"" normalcolor:kWhiteColor selectedColor:kWhiteColor frame:CGRectMake(21, 45, 20, 20) sel:@selector(closeBtnAction:)];
  39. self.announcement = [[QMUIButton alloc] initWithFrame:CGRectMake(self.width - 50 - 8, 45, 50, 20)];
  40. [self.announcement setTitle:@"公告" forState:UIControlStateNormal];
  41. [self.announcement setTitleColor:kWhiteColor forState:UIControlStateNormal];
  42. [self.announcement.titleLabel setFont:[UIFont systemFontOfSize:14]];
  43. [self.announcement addTarget:self action:@selector(handleAnnouncementEvent) forControlEvents:UIControlEventTouchUpInside];
  44. [self addSubview:self.announcement];
  45. UILabel *titleLab = [[UILabel alloc] init];
  46. titleLab.text = @"创建直播";
  47. titleLab.font = [UIFont boldSystemFontOfSize:18];
  48. titleLab.textColor = kWhiteColor;
  49. [self addSubview:titleLab];
  50. [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.centerX.equalTo(self);
  52. make.centerY.equalTo(self.announcement);
  53. }];
  54. // [self resetView];
  55. [GlobalVariables sharedInstance].isShop = NO;
  56. }
  57. return self;
  58. }
  59. - (void)handleAnnouncementEvent {
  60. __weak __typeof(self)weakSelf = self;
  61. [FanweMessage alertInput:nil message:@"请输入公告" placeholder:@"" keyboardType:UIKeyboardTypeDefault destructiveTitle:@"确认" destructiveAction:^(NSString *text) {
  62. weakSelf.announcement_str = text;
  63. } cancelTitle:@"取消" cancelAction:^{
  64. }];
  65. }
  66. -(void)resetView{
  67. // CGRectMake(15, 25, 65, kRealValue(45)
  68. [self.locationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.mas_equalTo(15);
  70. make.top.mas_equalTo(25);
  71. make.height.mas_equalTo(45);
  72. }];
  73. [self.passwordBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.mas_equalTo(self.locationBtn.mas_right).offset(10);
  75. make.top.mas_equalTo(25);
  76. make.height.mas_equalTo(45);
  77. }];
  78. [self.shopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.left.mas_equalTo(self.passwordBtn.mas_right).offset(10);
  80. make.top.mas_equalTo(25);
  81. make.height.mas_equalTo(45);
  82. }];
  83. }
  84. - (void)locationBtnAction:(ImageTitleButton *)sender
  85. {
  86. sender.selected = !sender.selected;
  87. self.isCanLocation = sender.selected;
  88. if (!self.isCanLocation) {
  89. [sender setTitle:ASLocalizedString(@"开启定位") forState:UIControlStateNormal];
  90. }
  91. [self resetView];
  92. }
  93. - (void)pravicyBtnAction:(ImageTitleButton *)sender
  94. {
  95. sender.selected = !sender.selected;
  96. self.pravicy = sender.selected;
  97. if (self.delegate && [self.delegate respondsToSelector:@selector(ispracychangeActionDelegate:)]) {
  98. [self.delegate ispracychangeActionDelegate:self.pravicy];
  99. }
  100. }
  101. - (void)passwordBtnAction:(ImageTitleButton *)sender
  102. {
  103. if ([BGUtils isBlankString:self.password]) {
  104. sender.selected = !sender.selected;
  105. }
  106. // self.passwordBtn = sender.selected;
  107. if (self.delegate && [self.delegate respondsToSelector:@selector(clickPasswordActionDelegate:)]) {
  108. [self.delegate clickPasswordActionDelegate:sender.selected];
  109. }
  110. }
  111. - (void)classifyBtnAction:(ImageTitleButton *)sender
  112. {
  113. if (self.delegate && [self.delegate respondsToSelector:@selector(classifyButtonActionDelegate)]) {
  114. [self.delegate classifyButtonActionDelegate];
  115. }
  116. }
  117. -(void)shopBtnAction:(ImageTitleButton *)sender{
  118. sender.selected = !sender.selected;
  119. self.isShop = sender.selected;
  120. [GlobalVariables sharedInstance].isShop = self.isShop;
  121. if (self.delegate && [self.delegate respondsToSelector:@selector(clickShopActionDelegate:)]) {
  122. [self.delegate clickShopActionDelegate:self.isShop];
  123. }
  124. }
  125. - (void)closeBtnAction:(UIButton *)sender
  126. {
  127. if (self.delegate && [self.delegate respondsToSelector:@selector(closeThePublishLive:)]) {
  128. [self.delegate closeThePublishLive:self];
  129. }
  130. }
  131. #pragma mark 获取到地理位置
  132. - (void)locationCityJudge
  133. {
  134. if ( self.BuguLive.province != nil && self.BuguLive.locationCity!=nil)
  135. {
  136. _locationCityString = self.BuguLive.locationCity;
  137. _provinceSrting = self.BuguLive.province;
  138. }
  139. else
  140. {
  141. _locationCityString =[self.BuguLive.appModel.ip_info objectForKey:@"city"];
  142. _provinceSrting =[self.BuguLive.appModel.ip_info objectForKey:@"province"];
  143. }
  144. }
  145. - (QMUIButton *)setButtomNormalImage:(NSString *)image selectedImage:(NSString *)selectedImage text:(NSString *)text normalcolor:(UIColor *)color selectedColor:(UIColor *)selecedColor frame:(CGRect)frame sel:(SEL)sel
  146. {
  147. QMUIButton *button = [QMUIButton buttonWithType:UIButtonTypeCustom];
  148. // [[ImageTitleButton alloc]initWithStyle: EImageLeftTitleRight];
  149. if (sel == @selector(closeBtnAction:)) {
  150. button = [QMUIButton buttonWithType:UIButtonTypeCustom];
  151. }
  152. button.frame = frame;
  153. [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
  154. [button setImage:[UIImage imageNamed:selectedImage] forState:UIControlStateSelected];
  155. [button setTitle:text forState:UIControlStateNormal];
  156. [button addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
  157. [button setTitleColor:color forState:UIControlStateNormal];
  158. [button setTitleColor:selecedColor forState:UIControlStateSelected];
  159. [button.titleLabel setFont:[UIFont systemFontOfSize:13]];
  160. button.spacingBetweenImageAndTitle = 5;
  161. button.imagePosition = QMUIButtonImagePositionLeft;
  162. button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  163. [self addSubview:button];
  164. return button;
  165. }
  166. @end