Image instead of title in navigation bar of TTLauncherView
Asked Answered
P

1

0

I use the TTLauncherView in my project. To have a custom navigation bar background I have subclassed the UINavigationBar in my app delegate. This works fine and all navigation bar's now have this custom style.

@implementation UINavigationBar (CustomNavBarBG)
-(void)drawRect:(CGRect)rect{
    UIImage *image = [UIImage imageNamed:@"navbar_s.png"];
    [image drawInRect:self.bounds];
}
@end

When navigating through the views the title appears in the middle of the bar. But on the navigation bar of the main screen, the launcher, I want to have an image instead of the title. Is this possible?

How to implement it?

Phosphide answered 26/9, 2011 at 15:5 Comment(0)
M
6

you can override the default title view when you load your controller with a custom UIView, such as a UIButton:

///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewDidLoad {
  [super viewDidLoad];

  UIButton *logoView = [[[UIButton alloc] initWithFrame:CGRectMake(0,0,85,40)] autorelease];
  [logoView setBackgroundImage:[UIImage imageNamed:@"navBarLogo.png"] forState:UIControlStateNormal];
  [logoView setUserInteractionEnabled:NO];

  self.navigationItem.titleView = logoView;
}

I'm actually not sure why I used UIButton here :-) maybe you can use a UIImageView instead, but this code works fine.

Myogenic answered 26/9, 2011 at 20:50 Comment(1)
it works with UIImageView but it stays on top of statusbar. Following one works neither: CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame]; CGRect rectImage = CGRectMake(0, rectStatus.size.height , width, height); [imageView setFrame:rectImage]; self.navigationItem.titleView = imageView;Diplococcus

© 2022 - 2024 — McMap. All rights reserved.