首页 > 代码库 > 导航视图栏左右键自定义

导航视图栏左右键自定义

//创建按钮初始化

UIButton * leftButton=[[UIButtonalloc]initWithFrame:CGRectMake(0, 0, 60, 24)];


//添加返回方法

   [leftButton addTarget:self action:@selector(backMainViewController) forControlEvents:UIControlEventTouchUpInside];


//设置字体颜色,状态

   [leftButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];


//设置字体内容,状态

   [leftButton setTitle:@"返回" forState:UIControlStateNormal];


//设置按钮图片,状态

   [leftButton setBackgroundImage:[UIImageimageNamed:@"item_cancel@2x副本.png"] forState:UIControlStateNormal];


//为导航栏左键添加控件

UIBarButtonItem * leftButtonItem=[[UIBarButtonItemalloc]initWithCustomView:leftButton];


//左键赋值

self.navigationItem.leftBarButtonItem = leftButtonItem;


[leftButton release];


本文出自 “Ghost霍的尛博客” 博客,请务必保留此出处http://ghost0714.blog.51cto.com/8682905/1411167