Objective c UIView图层圆角和-drawRect:
是否可以在Objective c UIView图层圆角和-drawRect:,objective-c,cocoa-touch,Objective C,Cocoa Touch,是否可以在UIView的图层上设置圆角,同时覆盖-drawRect:?当前,-drawRect:调用似乎覆盖了层的圆角,并使其再次呈现角度,即使-drawRect:仅包含对super的-drawRect:的调用,将不透明属性设置为否。您将获得圆角 -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if(self) { self.layer.cornerRadius
UIView
的图层上设置圆角,同时覆盖-drawRect:
?当前,-drawRect:
调用似乎覆盖了层的圆角,并使其再次呈现角度,即使-drawRect:
仅包含对super的-drawRect:
的调用,将不透明属性设置为否。您将获得圆角
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if(self)
{
self.layer.cornerRadius = KCORNERRAD;
self.opaque = NO;
}
return self;
}
self.opaque=NO
对我不起作用。设置self.layer.masksToBounds=YES
确实有效(在iOS 4.3上测试):
这里也一样
self.opaque=NO
没有这样做,但是masksToBounds=YES
做了。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if( self )
{
self.layer.cornerRadius = 6.0f;
self.layer.masksToBounds = YES;
}
return self;
}