iOS 自定义NavigationBar右侧按钮rightBarButtonItem--button

//两个按钮的父类view
    UIView *rightButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
//历史浏览按钮
    UIButton *historyBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    [rightButtonView addSubview:historyBtn];
    [historyBtn setImage:[UIImage imageNamed:@"button_history"] forState:UIControlStateNormal];
    [historyBtn addTarget:self action:@selector(historyBtnEvent) forControlEvents:UIControlEventTouchUpInside];

    //主页搜索按钮
    UIButton *mainAndSearchBtn = [[UIButton alloc] initWithFrame:CGRectMake(50, 0, 50, 50)];
    [rightButtonView addSubview:mainAndSearchBtn];
    [mainAndSearchBtn setImage:[UIImage imageNamed:@"button_filter-"] forState:UIControlStateNormal];
    [mainAndSearchBtn addTarget:self action:@selector(mainAndSearchBtnEvent) forControlEvents:UIControlEventTouchUpInside];

    //把右侧的两个按钮添加到rightBarButtonItem
    UIBarButtonItem *rightCunstomButtonView = [[UIBarButtonItem alloc] initWithCustomView:rightButtonView];
    self.navigationItem.rightBarButtonItem = rightCunstomButtonView;
时间: 2024-08-13 03:39:31

iOS 自定义NavigationBar右侧按钮rightBarButtonItem--button的相关文章

iOS自定义的UISwitch按钮

UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc]initWithFrame:CGRectMake(200.0,10.0,0.0,0.0)]; 是不是很奇怪,大小竟然是0.0×0.0,没错,系统会自动帮你决定最佳的尺寸,你自己写的尺寸会被忽略掉,你只要定义好相对父视图的位置就好了.默认尺寸为79 * 27. 二.显示控件 [ parrentView

iOS自定义NavigationBar

日常开发中少不了用到UINavigationController,但是很多情况都要自定义NavigationBar.依稀记得自己刚开始也踩了好多坑,凑今天有空,就把想到的写下来.有时间了,考虑再把自定义TabBar写一下. 1.修改Navigationbar navigationBar其实有三个子视图,leftBarButtonItem,rightBarButtonItem,以及titleView. 1.1  方法一:alloc一个UINavigationBar ,并给alloc出来的Navig

iOS 自定义UINavigationController返回按钮

主要代码如下: //自定义导航栏返回按钮 self.navigationItem.leftBarButtonItem = ({ //导航栏返回背景视图 UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 160, 44)]; //返回按钮 UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 12, 20, 20)]; [button setBackg

修改navigationbar右侧按钮离屏幕边缘位置

先上代码 UIButton *settingBtn = [Utils creatCustomButtonWithFrame:CGRectMake(0, 0, 60, 40) btnTitle:@"设置" btnFontSize:14 titleColor:[UIColor blackColor]]; [settingBtn addTarget:self action:@selector(clickTheSettingBtn) forControlEvents:UIControlEven

Navigationbar 右侧按钮

UIBarButtonItem *updateButton = [[UIBarButtonItem alloc] initWithTitle:@"修改" style:UIBarButtonItemStylePlain target:self action:@selector(updateInfo)]; self.navigationItem.rightBarButtonItem = updateButton;

iOS 为导航栏自定义按钮图案Button Image 运行出来的颜色与原本颜色不一样 -解决方案

为相机制作闪光灯,在导航栏自定义了"闪光"图案,希望点击时变换图片,但是一直没有改变,原来是因为设置了Global Tint的颜色,所以系统会自动把图片的颜色改为Global Tint的颜色. 解决方案,设置图片时,添加:imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal 源码: - (void) setFlashOn:(BOOL)isOn { if (self.captureDevice.hasFlash) { UIIm

[iOS微博项目 - 1.5] - NavigationBar标题按钮

A.NavigationBar标题按钮 1.需求 在“首页”的导航栏中部设置一个“首页”文字+箭头按钮 统一设置样式 根据实际文本长度调整宽度 消除系统自带的点击高亮效果 点击按钮,箭头上下颠倒 github: https://github.com/hellovoidworld/HVWWeibo 2.思路 使用UIButton,设置文本和图片 在initWithFrame统一样式 创建一个继承UIButton的自定义类,重写文本和图片的绘图方法,互换位置 设置一个标识成员变量,判断当前的按钮状态

iOS系列 基础篇 06 标签和按钮 (Label & Button)

iOS系列 基础篇 06 标签和按钮 (Label & Button) 目录: 标签控件 按钮控件 小结 标签和按钮是两个常用的控件,下面咱们逐一学习. 1. 标签控件 使用Single View Application模板创建一个名为“LabelAndButtonSimple”的工程 (PS:具体创建过程和各设置项介绍等可参见前面的文章,这里就截图简单带过了:) (1) 打开Xcode,选择Create a new Xcode Project: (2) 选择Single View Applic

IOS 自定义UIBUTTON 直接拖个xib 就能在button上显示多行文本 并且添加了点击的效果

拖个button继承一下  几行代码 就搞定 自用效果还行 IOS 自定义UIBUTTON 直接拖个xib 就能在button上显示多行文本 并且添加了点击的效果,布布扣,bubuko.com