我將角半徑應用於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