@@ -102,7 +102,7 @@ - (void)customizeTabBarForController:(CYLTabBarController *)tabBarController {
102
102
103
103
- (void )customizeInterface {
104
104
[self setUpNavigationBarAppearance ];
105
- [self setUpTabBarItemTextAttributes ];
105
+ // [self setUpTabBarItemTextAttributes];
106
106
}
107
107
/* *
108
108
* 设置navigationBar样式
@@ -143,21 +143,60 @@ - (void)setUpNavigationBarAppearance {
143
143
*/
144
144
- (void )setUpTabBarItemTextAttributes {
145
145
146
+
147
+ // set the text color for unselected state
146
148
// 普通状态下的文字属性
147
149
NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary ];
148
- normalAttrs[NSForegroundColorAttributeName ] = [UIColor grayColor ];
150
+ normalAttrs[NSForegroundColorAttributeName ] = [UIColor blackColor ];
149
151
152
+ // set the text color for selected state
150
153
// 选中状态下的文字属性
151
154
NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary ];
152
- selectedAttrs[NSForegroundColorAttributeName ] = [UIColor darkGrayColor ];
155
+ selectedAttrs[NSForegroundColorAttributeName ] = [UIColor blackColor ];
153
156
157
+ // set the text Attributes
154
158
// 设置文字属性
155
159
UITabBarItem *tabBar = [UITabBarItem appearance ];
156
160
[tabBar setTitleTextAttributes: normalAttrs forState: UIControlStateNormal];
157
161
[tabBar setTitleTextAttributes: normalAttrs forState: UIControlStateHighlighted];
158
162
163
+ // Set the dark color to selected tab (the dimmed background)
164
+ // TabBarItem选中后的背景颜色
165
+ [[UITabBar appearance ] setSelectionIndicatorImage: [AppDelegate imageFromColor: [UIColor colorWithRed: 26 /255.0 green: 163 /255.0 blue: 133 /255.0 alpha: 1 ] forSize: CGSizeMake ([UIScreen mainScreen ].bounds.size.width/5 .0f , 49 ) withCornerRadius: 0 ]];
166
+
167
+ // set the bar background color
159
168
// 设置背景图片
160
- // UITabBar *tabBarAppearance = [UITabBar appearance];
161
- // [tabBarAppearance setBackgroundImage:[UIImage imageNamed:@"tabbar_background_os7"]];
169
+ UITabBar *tabBarAppearance = [UITabBar appearance ];
170
+ [tabBarAppearance setBackgroundImage: [UIImage imageNamed: @" tabbar_background_os7" ]];
171
+ }
172
+
173
+ + (UIImage *)imageFromColor : (UIColor *)color forSize : (CGSize )size withCornerRadius : (CGFloat )radius
174
+ {
175
+ CGRect rect = CGRectMake (0 , 0 , size.width , size.height );
176
+ UIGraphicsBeginImageContext (rect.size );
177
+
178
+ CGContextRef context = UIGraphicsGetCurrentContext ();
179
+ CGContextSetFillColorWithColor (context, [color CGColor ]);
180
+ CGContextFillRect (context, rect);
181
+
182
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext ();
183
+ UIGraphicsEndImageContext ();
184
+
185
+ // Begin a new image that will be the new image with the rounded corners
186
+ // (here with the size of an UIImageView)
187
+ UIGraphicsBeginImageContext (size);
188
+
189
+ // Add a clip before drawing anything, in the shape of an rounded rect
190
+ [[UIBezierPath bezierPathWithRoundedRect: rect cornerRadius: radius] addClip ];
191
+ // Draw your image
192
+ [image drawInRect: rect];
193
+
194
+ // Get the image, here setting the UIImageView image
195
+ image = UIGraphicsGetImageFromCurrentImageContext ();
196
+
197
+ // Lets forget about that we were drawing
198
+ UIGraphicsEndImageContext ();
199
+
200
+ return image;
162
201
}
163
202
@end
0 commit comments