Search code examples
uinavigationbarsubclassing

Subclass of UINavigationBar - Setting translucent to YES not working


Not sure if this is the correct approach but subclassing a UINavigationBar and setting it's translucent to YES doesn't seem to work.

In my implementation file:

- (void)drawRect:(CGRect)rect
{
    self.translucent = YES;
}

I was able to override it within a view controller, however, i find myself repeating code and would like to move the implementation in the custom class.

Any thoughts?


Solution

  • Found a solution if anyone needs it. Set self.translucent to YES on init:

    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            self.translucent = YES;
        }
        return self;
    }
    
    - (void)drawRect:(CGRect)rect
    {
    
    }