Last active
August 29, 2015 14:05
-
-
Save gbarcena/e5e6ad3668bccc240a68 to your computer and use it in GitHub Desktop.
Rounding Image Corners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)setupButton:(UIButton *)button bounds:(CGRect)bounds cornerRadius:(CGFloat)cornerRadius bgColor:(UIColor *)bgColor | |
{ | |
UIImage *image = [[self class] imageWithFrame:bounds | |
cornerRadius:cornerRadius | |
roundingCorners:UIRectCornerBottomLeft | |
bgColor:bgColor]; | |
[button setBackgroundImage:image forState:UIControlStateNormal]; | |
button.backgroundColor = [UIColor clearColor]; | |
[button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted]; | |
} | |
+(UIImage *)imageWithFrame:(CGRect)frame | |
cornerRadius:(CGFloat)cornerRadius | |
roundingCorners:(UIRectCorner)roundingCorners | |
bgColor:(UIColor *)bgColor | |
{ | |
//// General Declarations | |
UIGraphicsBeginImageContext(frame.size); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(CGRectGetMinX(frame), | |
CGRectGetMinY(frame), | |
CGRectGetWidth(frame), | |
CGRectGetHeight(frame)) | |
byRoundingCorners:roundingCorners | |
cornerRadii:CGSizeMake(cornerRadius, cornerRadius)]; | |
CGContextSaveGState(context); | |
[bgColor setFill]; | |
[roundedRectanglePath fill]; | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
CGContextRestoreGState(context); | |
UIGraphicsEndImageContext(); | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment