@@ -180,37 +180,20 @@ - (void)customizeTabBarSelectionIndicatorImage {
180
180
CGSize selectionIndicatorImageSize = CGSizeMake (CYLTabBarItemWidth, tabBarHeight);
181
181
// Get initialized tabbar if exists.
182
182
UITabBar *tabBar = [self cyl_tabBarController ].tabBar ?: [UITabBar appearance ];
183
- [tabBar setSelectionIndicatorImage: [[self class ]
184
- imageFromColor: [UIColor yellowColor ]
185
- forSize: selectionIndicatorImageSize
186
- withCornerRadius: 0 ]];
183
+ [tabBar setSelectionIndicatorImage:
184
+ [[self class ] imageWithColor: [UIColor redColor ]
185
+ size: selectionIndicatorImageSize]];
187
186
}
188
187
189
- + (UIImage *)imageFromColor : (UIColor *)color forSize : (CGSize )size withCornerRadius : ( CGFloat ) radius {
190
- CGRect rect = CGRectMake ( 0 , 0 , size.width , size.height ) ;
191
- UIGraphicsBeginImageContext ( rect. size );
192
-
188
+ + (UIImage *)imageWithColor : (UIColor *)color size : (CGSize )size {
189
+ if (!color || size.width <= 0 || size.height <= 0 ) return nil ;
190
+ CGRect rect = CGRectMake ( 0 . 0f , 0 . 0f , size. width + 1 , size. height );
191
+ UIGraphicsBeginImageContextWithOptions (rect. size , NO , 0 );
193
192
CGContextRef context = UIGraphicsGetCurrentContext ();
194
- CGContextSetFillColorWithColor (context, [ color CGColor ] );
193
+ CGContextSetFillColorWithColor (context, color. CGColor );
195
194
CGContextFillRect (context, rect);
196
-
197
195
UIImage *image = UIGraphicsGetImageFromCurrentImageContext ();
198
196
UIGraphicsEndImageContext ();
199
-
200
- // Begin a new image that will be the new image with the rounded corners
201
- // (here with the size of an UIImageView)
202
- UIGraphicsBeginImageContext (size);
203
-
204
- // Add a clip before drawing anything, in the shape of an rounded rect
205
- [[UIBezierPath bezierPathWithRoundedRect: rect cornerRadius: radius] addClip ];
206
- // Draw your image
207
- [image drawInRect: rect];
208
-
209
- // Get the image, here setting the UIImageView image
210
- image = UIGraphicsGetImageFromCurrentImageContext ();
211
-
212
- // Lets forget about that we were drawing
213
- UIGraphicsEndImageContext ();
214
197
return image;
215
198
}
216
199
0 commit comments