Skip to content

Instantly share code, notes, and snippets.

@zhangwc
Created August 28, 2013 14:23
Show Gist options
  • Save zhangwc/6366569 to your computer and use it in GitHub Desktop.
Save zhangwc/6366569 to your computer and use it in GitHub Desktop.
#import <QuartzCore/QuartzCore.h>
@implementation UIView (RectCorner)
- (void)setCornerOnTop {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
cornerRadii:CGSizeMake(8.0, 8.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
[maskLayer release];
}
- (void)setCornerOnBottom {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)
cornerRadii:CGSizeMake(8.0, 8.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
[maskLayer release];
}
- (void)setAllCorner {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
cornerRadius:8.0];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
[maskLayer release];
}
- (void)setNoneCorner {
self.layer.mask = nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment