开发者

UIView layer rounded corners and -drawRect:

Is it possible to set rounded corners on an UIView's layer and override -drawRect: at the same time? Currently the -开发者_如何转开发drawRect: call seems to override the layer's rounded corners and make them appear angular again, even if the -drawRect: just contains a call to the super's -drawRect:.


self.opaque = NO didn't work for me. Setting self.layer.masksToBounds = YES did work, however (tested on iOS 4.3):

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if( self )
    {
        self.layer.cornerRadius = 6.0f;
        self.layer.masksToBounds = YES;
    }
    return self;
}


Set the opaque property to NO. You will get your rounded corners back.

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        self.layer.cornerRadius = KCORNERRAD;
        self.opaque = NO;

    }
    return self;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜