TTLauncherView 导航栏中的图像而不是标题 [英] Image instead of title in navigation bar of TTLauncherView

查看:20
本文介绍了TTLauncherView 导航栏中的图像而不是标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用了 TTLauncherView.为了拥有自定义导航栏背景,我在我的应用程序委托中对 UINavigationBar 进行了子类化.这工作正常,所有导航栏现在都有这种自定义样式.

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?

如何实施?

推荐答案

当您使用自定义 UIView(例如 UIButton)加载控制器时,您可以覆盖默认标题视图:

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;
}

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

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

这篇关于TTLauncherView 导航栏中的图像而不是标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆