我有一个带有导航栏的详细视图,带有后退按钮和视图名称.
导航栏以编程方式设置.
显示的名称设置如下.
导航栏以编程方式设置.
显示的名称设置如下.
self.title = NSLocalizedString(name,@“”);
名称取决于显示的视图.
现在我想在导航栏上显示一个小图标,这也取决于视图.
我怎么做?
解决方法
您可以将backGround图像设置为navigationBar使用此选项
输入didFinishLaunchingWithOptions
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"title_bar.png"] forBarMetrics:UIBarMetricsDefault];
或者您可以使用任何视图设置导航栏图像
UINavigationBar *navBar = [[self navigationController] navigationBar]; UIImage *image = [UIImage imageNamed:@"TopBar.png"]; [navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
或者您可以在NavigationBar Link上设置视图
[[UINavigationBar appearance] addSubview:yourView];
要么
self.navigationItem.titleView = YourView;
并使用h设置标题
self.navigationItem.title = @"Your Title";
你可以使用这个获得navigationBarButton
-(void)getRightBarBtn { UIButton *Btn =[UIButton buttonWithType:UIButtonTypeCustom]; [Btn setFrame:CGRectMake(0.0f,0.0f,68.0f,30.0f)]; [Btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"yourImage.png"]] forState:UIControlStateNormal]; //[Btn setTitle:@"OK" forState:UIControlStateNormal]; //Btn.titleLabel.font = [UIFont fontWithName:@"Georgia" size:14]; [Btn addTarget:self action:@selector(yourBtnPress:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithCustomView:Btn]; [self.navigationItem setRightBarButtonItem:addButton]; }
并在导航栏上设置简单的imageView
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"star.png"]]; UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithCustomView:image]; self.navigationItem.rightBarButtonItem = backBarButton;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。