1. Custom button
The code is as follows |
Copy Code |
Left button UIButton *leftbtn = [[UIButton Alloc]initwithframe:rectwithpara (-20, 0, 44, 44)]; [Leftbtn addtarget:self Action: @selector (btnclicked:) forcontrolevents:uicontroleventtouchupinside];//Set Button click event [Leftbtn setbackgroundimage:imagenamed (@ "ic_fanhui_normal.png") forstate:uicontrolstatenormal];//set button normal state picture [Leftbtn setbackgroundimage:imagenamed (@ "ic_fanhui_pressed.png") forstate:uicontrolstateselected];//Settings button Select Picture
|
2. Initialization of Uibarbuttonitem
The code is as follows |
Copy Code |
Uibarbuttonitem *leftbarbuton = [[Uibarbuttonitem alloc]initwithcustomview:leftbtn]; |
3. Adjust the position and set the left icon of the navigation bar
code is as follows |
copy code |
//adjustments Leftbarbuttonitem the position under IOS7 if (([[[[[[[Uidevice Currentdevice] systemversion] floatvalue]>=7.0?20:0)) { uibarbuttonitem *negativespacer = [[Uibarbuttonitem alloc]initwithbarbuttonsystemitem: Uibarbuttonsystemitemfixedspace Target:nil Action:nil]; negativespacer.width = -20;//This value can be changed freely according to the situation Self.navigationItem.leftBarButtonItems = @[negativespacer, Leftbarbuton]; }else self.navigationItem.leftBarButtonItem = Leftbarbuton; |