Skip to content

Commit 3d9be8b

Browse files
committed
fix bug for setSelectionIndicatorImage
1 parent 2a43564 commit 3d9be8b

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

Example/CYLTabBarControllerConfig.m

+8-25
Original file line numberDiff line numberDiff line change
@@ -180,37 +180,20 @@ - (void)customizeTabBarSelectionIndicatorImage {
180180
CGSize selectionIndicatorImageSize = CGSizeMake(CYLTabBarItemWidth, tabBarHeight);
181181
//Get initialized tabbar if exists.
182182
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]];
187186
}
188187

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);
193192
CGContextRef context = UIGraphicsGetCurrentContext();
194-
CGContextSetFillColorWithColor(context, [color CGColor]);
193+
CGContextSetFillColorWithColor(context, color.CGColor);
195194
CGContextFillRect(context, rect);
196-
197195
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
198196
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();
214197
return image;
215198
}
216199

0 commit comments

Comments
 (0)