Skip to content

Instantly share code, notes, and snippets.

@JigarM
Created December 30, 2014 00:56
Show Gist options
  • Save JigarM/cb58580735b50773015f to your computer and use it in GitHub Desktop.
Save JigarM/cb58580735b50773015f to your computer and use it in GitHub Desktop.
UIView Category for Round Corner of UIView
//
// 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
//
// 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
@JigarM
Copy link
Author

JigarM commented Dec 30, 2014

You can use this Category by Calling :

[self.profile addRoundedCorners:UIRectCornerTopLeft| UIRectCornerBottomRight| UIRectCornerBottomLeft
                    withRadii:CGSizeMake(25.0f, 25.0f)];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment