标签:ios leftbutton 自定义返回按钮
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;
标签:ios leftbutton 自定义返回按钮
原文地址:http://blog.csdn.net/gorgeous_xie/article/details/42001835