ios - ios自定义导航栏

标签 ios objective-c iphone xcode uinavigationcontroller

我在 StroryBoard 中使用了 Navigation Controller 和 navigation Bar。

我想为一个 View 自定义导航栏,如下所示,用于导航栏的右侧。

enter image description here

我试过的代码

    UIButton *btn_list=[UIButton buttonWithType:UIButtonTypeCustom];
    btn_list.frame=CGRectMake(0, 0, 60, 30);
    [btn_list setTitle:@"Liste" forState:UIControlStateNormal];
    [btn_list setBackgroundImage:[UIImage imageNamed:@"red-left.png"] forState:UIControlStateNormal];
    [btn_list setBackgroundImage:[UIImage imageNamed:@"black-left.png"] forState:UIControlStateSelected];
    UIBarButtonItem *list_bar=[[UIBarButtonItem alloc]initWithCustomView:btn_list];
    
    UIButton *btn_map=[UIButton buttonWithType:UIButtonTypeCustom];
    btn_map.frame=CGRectMake(0, 0, 60, 30);
    [btn_map setTitle:@"Karte" forState:UIControlStateNormal];
    [btn_map setBackgroundImage:[UIImage imageNamed:@"red-right.png"] forState:UIControlStateNormal];
    [btn_list setBackgroundImage:[UIImage imageNamed:@"black-right.png"] forState:UIControlStateSelected];
    UIBarButtonItem *map_bar=[[UIBarButtonItem alloc]initWithCustomView:btn_map];

    self.navigationItem.rightBarButtonItems=[[NSArray alloc]initWithObjects:list_bar,map_bar, nil];

试过的代码问题:两个按钮之间有一个空格。

我怎样才能做到这一点?

最佳答案

只要使用分段控制:你有一个完整的例子HERE

关于ios - ios自定义导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25928097/

相关文章:

ios - 使用由两个远点定义的半径绘制的 MKCircle 渲染不正确

objective-c - NSComboBox : How to tell user has typed in information that is not in the pop up list and read it

objective-c - 为什么一个空的 UIScrollView 有两个 subview ?

ios - 是否可以确定是否已提交 SKStore Review Controller。

iphone - Sqlite 数据库被锁定且数据库繁忙 Issues

iphone - 无论设备方向如何,如何保持 UIView 指向某个方向?

ios - 如何深度链接到 OpenTable

ios - 来自 Swift 代码的抗锯齿像素被 OpenCV 转换为不需要的黑色像素

android - 可点击的网站图像无法在 iPhone 和 Android 设备上运行

ios - 魔法记录,无法保存对象 : contextDidSave == NO, error = nil