您的位置:首页 > 产品设计 > UI/UE

设置UIView圆角 部分圆角

2014-05-22 11:11 435 查看
.h文件
</pre><pre code_snippet_id="357860" snippet_file_name="blog_20140522_1_4615163" name="code" class="objc">@interface UIView (RectCorner)
- (void)setCornerOnTop;
- (void)setCornerOnBottom;
- (void)setAllCorner;
- (void)setNoneCorner;
@end


.m 文件
</pre><pre>
@implementation UIView (RectCorner)
- (void)setCornerOnTop
{
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
cornerRadii:CGSizeMake(10.0f, 10.0f)];
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(10.0f, 10.0f)];
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:10.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;
}

@end



转载自:http://blog.csdn.net/reylen/article/details/22038607
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: