Commit 83b902f342601b24408cadf90d478f3086aaf93a

Authored by yanglingyu
1 parent e49f9f8f

一级菜单颜色修改

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