iphone – 如何在NavBar中以编程方式设置图片?
发布时间:2020-12-14 17:10:13 所属栏目:百科 来源:网络整理
导读:我有一个带有导航栏的详细视图,带有后退按钮和视图名称. 导航栏以编程方式设置. 显示的名称设置如下. self.title = NSLocalizedString(name,@“”); 名称取决于显示的视图. 现在我想在导航栏上显示一个小图标,这也取决于视图. 我怎么做? 解决方法 您可以将b
我有一个带有导航栏的详细视图,带有后退按钮和视图名称.
导航栏以编程方式设置. 显示的名称设置如下. 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; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |