Set a custom subclass of UINavigationBar in UINavigationController programmatically

前端 未结 12 1522
清歌不尽
清歌不尽 2020-11-28 17:29

Does anyone know how can I use my custom subclass of UINavigationBar if I instantiate UINavigationController programmatically (without IB)?

<
12条回答
  •  春和景丽
    2020-11-28 18:06

    Michael's solution works, but you can avoid NSKeyedArchiver and 'xxd' utility. Simply Subclass UINavigationController and override initWithRootViewController, loading your custom NavigationController NIB directly:

    - (id) initWithRootViewController:(UIViewController *)rootViewController
    {
        [self release];
        self = [[[[NSBundle mainBundle] loadNibNamed:@"CTNavigationController" owner:nil options:nil] objectAtIndex:0] retain];  
        [self setViewControllers:[NSArray arrayWithObject:rootViewController]];
        return self;
    }
    

提交回复
热议问题