Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:.

like image 948
Era Avatar asked Aug 16 '11 13:08

Era


1 Answers

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;
}
like image 83
dvs Avatar answered Nov 15 '22 05:11

dvs