我将角半径应用于UIView
,即UIRectCornerTopLeft
和UIRectCornerTopRight
。当我申请这个时,边界在角落里消失了。如何避免这种情况?如何制作带有可选圆角和边框的UIView?
这是我如何适用边界UIView
:
[self.middleView addRoundedCorners:UIRectCornerTopLeft|UIRectCornerTopRight withRadii:CGSizeMake(4, 4)];
self.middleView.layer.borderWidth = 0.5f;
self.middleView.layer.borderColor = [[UIColor colorWith8BitRed:0 green:0 blue:0 alpha:0.25]
这是我使用的应用可选圆角的类别:
#import "UIView+Roundify.h"
@implementation 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;
}
你的意思是可选的圆角和边框? –
@icodes尝试将'strokeColor'设置为'CAShapeLayer * maskLayer' – Akhilrajtr
请参阅此处的答案:http://stackoverflow.com/questions/12756928/cashapelayer-with-border-and-fill-color-and-rounding – n00bProgrammer