Created
December 30, 2014 00:56
-
-
Save JigarM/cb58580735b50773015f to your computer and use it in GitHub Desktop.
UIView Category for Round Corner of UIView
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
// | |
// UIView+UIView_Roundify.h | |
// JMCurvedView | |
// | |
// Created by Mobmaxime on 30/12/14. | |
// Copyright (c) 2014 Jigar. All rights reserved. | |
// | |
//========================================================================== | |
//Round two corners in UIView | |
//stackoverflow.com/questions/4847163/round-two-corners-in-uiview | |
//========================================================================== | |
#import <UIKit/UIKit.h> | |
@interface UIView (UIView_Roundify) | |
-(void)addRoundedCorners:(UIRectCorner)corners withRadii:(CGSize)radii; | |
-(CALayer*)maskForRoundedCorners:(UIRectCorner)corners withRadii:(CGSize)radii; | |
@end |
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
// | |
// UIView+UIView_Roundify.m | |
// JMCurvedView | |
// | |
// Created by Mobmaxime on 30/12/14. | |
// Copyright (c) 2014 Jigar. All rights reserved. | |
// | |
//========================================================================== | |
//Round two corners in UIView | |
//stackoverflow.com/questions/4847163/round-two-corners-in-uiview | |
//========================================================================== | |
#import "UIView+UIView_Roundify.h" | |
#import <QuartzCore/QuartzCore.h> | |
@implementation UIView (UIView_Roundify) | |
-(void)addRoundedCorners:(UIRectCorner)corners withRadii:(CGSize)radii { | |
CALayer *tMaskLayer = [self maskForRoundedCorners:corners withRadii:radii]; | |
self.layer.mask = tMaskLayer; | |
} | |
-(CALayer*)maskForRoundedCorners:(UIRectCorner)corners withRadii:(CGSize)radii { | |
CAShapeLayer *maskLayer = [CAShapeLayer layer]; | |
maskLayer.frame = self.bounds; | |
UIBezierPath *roundedPath = [UIBezierPath bezierPathWithRoundedRect: | |
maskLayer.bounds byRoundingCorners:corners cornerRadii:radii]; | |
maskLayer.fillColor = [[UIColor whiteColor] CGColor]; | |
maskLayer.backgroundColor = [[UIColor clearColor] CGColor]; | |
maskLayer.path = [roundedPath CGPath]; | |
return maskLayer; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use this Category by Calling :