7

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

John Topley
  • 110,534
  • 45
  • 192
  • 237
Era
  • 30,460
  • 24
  • 136
  • 197

2 Answers2

15

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;
}
dvs
  • 12,224
  • 6
  • 39
  • 45
3

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;
}
Warren Burton
  • 17,121
  • 3
  • 50
  • 72