Commit 83b902f342601b24408cadf90d478f3086aaf93a

Authored by yanglingyu
1 parent e49f9f8f

一级菜单颜色修改

CNLiveScioLive/Pages/Home/CNHomeModel.h
... ... @@ -15,6 +15,7 @@
15 15 @property (nonatomic, copy) NSString *subTitle;
16 16 @property (nonatomic, copy) NSString *titleColor;
17 17 @property (nonatomic, copy) NSString *tagsColor;
  18 +@property (nonatomic, copy) NSString *textColor;
18 19  
19 20  
20 21 @property (nonatomic, copy) NSString *ID;
... ...
CNLiveScioLive/Pages/Home/CNHomeViewController.m
... ... @@ -67,10 +67,14 @@
67 67  
68 68 NSMutableArray *controllers = [NSMutableArray array];
69 69 NSMutableArray *titles = [NSMutableArray array];
70   -
  70 + NSMutableArray *colors = [NSMutableArray array];
71 71 for(int i = 0; i < self.data.count; i++){
72 72 CNHomeModel *model = self.data[i];
73 73 [titles addObject:model.title];
  74 + if (!model.textColor) {
  75 + model.textColor = @"";
  76 + }
  77 + [colors addObject:model.textColor];
74 78 if ([model.cid isEqualToString:@"wz/toutiao/"]) {
75 79 //外宣要闻
76 80 CNLiveHeraldedNewsViewController *vc = [[CNLiveHeraldedNewsViewController alloc] init];
... ... @@ -93,12 +97,10 @@
93 97  
94 98 }
95 99 if(controllers.count > 0){
96   - self.segmentControl.titles = titles;
97   - if (ininavArray[0][@"textColor"]&&![ininavArray[0][@"textColor"] isEqualToString:@""]) {
98   -
99   - self.segmentControl.titleSelectColor = [UIColor colorWithHexString:ininavArray[0][@"textColor"]];
100   - [self.segmentControl setBottomViewColor:[UIColor colorWithHexString:ininavArray[0][@"textColor"]]];
101   - }
  100 + NSMutableArray *textArray = [NSMutableArray array];
  101 + [textArray addObject:titles];
  102 + [textArray addObject:colors];
  103 + self.segmentControl.titles = textArray;
102 104 self.segmentControl.viewControllers = controllers;
103 105 }
104 106 NSDictionary *dic = @{@"titles":titles};
... ...
CNLiveScioLive/Pages/Tools/ZXWSegmentControl/ZXWSegmentControl.h
... ... @@ -28,6 +28,10 @@
28 28 * 标题数组
29 29 */
30 30 @property (strong, nonatomic) NSArray * titles;
  31 +/**
  32 + *选中标题颜色
  33 + */
  34 +@property (strong, nonatomic) NSArray *textColors;
31 35  
32 36 /**
33 37 * 控制器数组
... ...
CNLiveScioLive/Pages/Tools/ZXWSegmentControl/ZXWSegmentControl.m
... ... @@ -90,7 +90,12 @@ typedef NS_ENUM(NSInteger, ScrollCtrlViewScrollStatus) {
90 90 if ([subview isKindOfClass:[ZXWSegment class]]) {
91 91 ZXWSegment * segment = (ZXWSegment *)subview;
92 92 segment.titleNormalColor = self.titleNormalColor;
  93 + NSString *textColor = self.textColors[segment.tag - 1995];
  94 + if (textColor&&![textColor isEqualToString:@""]) {
  95 + segment.titleSelectColor = [UIColor colorWithHexString:textColor];
  96 + }else{
93 97 segment.titleSelectColor = self.titleSelectColor;
  98 + }
94 99 segment.isTitleScale = self.isTitleScale;
95 100 }
96 101 }
... ... @@ -204,18 +209,18 @@ typedef NS_ENUM(NSInteger, ScrollCtrlViewScrollStatus) {
204 209 #pragma mark - Custom Accessors
205 210  
206 211 - (void)setTitles:(NSArray *)titles {
207   - _titles = titles;
208   -
  212 + _titles = titles[0];
  213 + _textColors = titles[1];
209 214 // Item的宽度
210 215 CGFloat itemW = 0.0;
211 216 CGFloat itemX = 0.0;
212   - for (int i = 0; i < titles.count; i ++) {
  217 + for (int i = 0; i < _titles.count; i ++) {
213 218 // 判断是滑动还是静止标题栏
214 219 if (self.isScrollTitle == YES) {
215 220 // 滑动标题栏
216 221  
217 222 // 计算文本标签的Size
218   - CGSize labelSize = [self sizeWithText:titles[i] font:segementTitleNormalFont maxSize:CGSizeMake(ZXWkScreen_width, self.height)];
  223 + CGSize labelSize = [self sizeWithText:_titles[i] font:segementTitleNormalFont maxSize:CGSizeMake(ZXWkScreen_width, self.height)];
219 224 // 计算Item的宽度 Item的宽度 = 本标签的宽度 + 间距
220 225 itemW = labelSize.width + ZXWSegementViewTitlePadding / 2;
221 226 // 设置contentSize
... ... @@ -225,17 +230,21 @@ typedef NS_ENUM(NSInteger, ScrollCtrlViewScrollStatus) {
225 230 // 静止标题栏
226 231  
227 232 // Item的宽度
228   - itemW = ZXWkScreen_width / titles.count;
  233 + itemW = ZXWkScreen_width / _titles.count;
229 234 // Item的x值
230 235 itemX = i * itemW;
231 236 // 设置contentSize
232 237 self.segementScrollView.contentSize = CGSizeMake(ZXWkScreen_width, 0);
233 238 }
234 239 ZXWSegment * segment = [[ZXWSegment alloc] initWithFrame:CGRectMake(itemX, 0, itemW, self.height)];
235   - segment.title = titles[i];
  240 + segment.title = _titles[i];
236 241 segment.titleNormalColor = self.titleNormalColor;
  242 + NSString *textColor = _textColors[i];
  243 + if (textColor&&![textColor isEqualToString:@""]) {
  244 + segment.titleSelectColor = [UIColor colorWithHexString:textColor];
  245 + }else{
237 246 segment.titleSelectColor = self.titleSelectColor;
238   -
  247 + }
239 248 segment.titleSelectBold = YES;
240 249 segment.tag = 1995 + i;
241 250 [segment addTarget:self action:@selector(itemAction:) forControlEvents:UIControlEventTouchUpInside];
... ...