I'm designing a view controller in my storyboard. It contains a navigation bar at the top and a content view. I've set the constraints as
- Navigation bar's top space to top layout guide = 0
- Content view fills the remaining space (leading and trailing space to superview = 0 ; bottom space to superview = 0, top space to navigation bar =0)
Because I want to display the status bar, I'm using the top layout guide to make the navigation bar displayed just under it. It works with a standard UINavigationBar.
But I have custom navigation bar : I've created my own class inheriting UINavigationBar.
The problem is : when specifying this custom class for the navigation bar in the Identity Inspector of the interface builder, the bar is not at the right place when running the app.
Is there anything to add or modify in initWitFrame
or initWithCoder
, or something else to do, so my custom navigation bar will follow the constraints of my storyboard.
EDIT - source added
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// additional setup
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:(NSCoder *)aDecoder];
if (self) {
// same setup than initWithFrame:
}
return self;
}
- (void)drawRect:(CGRect)rect
{
//[self setFrame:rect]; navigation bar is not at the right place if uncommented
}
drawRect:
is automatically trigged, setting my navigation bar origin to (0,0). If y don't override it, I'm loosing some custom settings of my bar, especially the background color. Any clue? – zbMaxdrawRect:
? Can you show the source of your customUINavigationBar
? – Arek HolkodrawRect:
. But I'm loosing some point of the customization. I edit my post for source. – zbMax