标签:
1.自定义按钮
代码如下 | 复制代码 |
//左按钮 UIButton *leftBtn = [[UIButton alloc]initWithFrame:RectWithPara(-20, 0, 44, 44)]; [leftBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];//设置按钮点击事件 [leftBtn setBackgroundImage:ImageNamed(@"ic_fanhui_normal.png") forState:UIControlStateNormal ];//设置按钮正常状态图片 [leftBtn setBackgroundImage:ImageNamed(@"ic_fanhui_pressed.png") forState:UIControlStateSelected];//设置按钮选中图片 |
2.初始化UIBarButtonItem
代码如下 | 复制代码 |
UIBarButtonItem *leftBarButon = [[UIBarButtonItem alloc]initWithCustomView:leftBtn]; |
3.调整位置以及设置导航栏的左边图标
代码如下 | 复制代码 |
// 调整 leftBarButtonItem 在 iOS7 下面的位置 if(([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0?20:0)) { UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; negativeSpacer.width = -20;//这个数值可以根据情况自由变化 self.navigationItem.leftBarButtonItems = @[negativeSpacer, leftBarButon]; }else self.navigationItem.leftBarButtonItem = leftBarButon; |
标签:
原文地址:http://www.cnblogs.com/xiaoxiaoyublogs/p/5439621.html