TTLauncherView导航栏中的图像而不是标题

Upv*_*ote 0 uinavigationcontroller three20 ttlauncherview

我在我的项目中使用TTLauncherView.要拥有自定义导航栏背景,我已在我的应用委托中将UINavigationBar子类化.这很好用,所有导航栏现在都有这种自定义样式.

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

浏览视图时,标题会显示在栏的中间.但是在主屏幕的导航栏上,启动器,我想要一个图像而不是标题.这可能吗?

怎么实现呢?

apo*_*rat 6

使用自定义UIView加载控制器时,可以覆盖默认标题视图,例如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;
}
Run Code Online (Sandbox Code Playgroud)

我实际上不确定为什么我在这里使用UIButton :-)也许你可以使用UIImageView,但这段代码工作正常.