Solve the problem of customizing the left button of the navigation bar on the right after ios7.0

Source: Internet
Author: User

1. Custom button

// left button

UIButton *leftbtn = [[UIButtonalloc]initwithframe:rectwithpara(- 0, (, )] ;

< Span style= "COLOR: #ffad10" >        [leftbtn addtarget: self action: @ Selector (btnclicked:) forcontrolevents: uicontroleventtouchupinside];//set button click event

< Span style= "Color:rgb (255,173,16)" >       [leftbtn setbackgroundimage: imagenamed @" Ic_fanhui_normal.png " Span style= "Color:rgb (255,173,16)") Forstate: Uicontrolstatenormal //set button normal state picture

[leftbtn setbackgroundimage:imagenamed(@ "Ic_fanhui_pressed.png" )forstate:uicontrolstateselected];//Set button to select the picture

2. Initialize Uibarbuttonitem

uibarbuttonitem *leftbarbuton = [[uibarbuttonitemalloc]initwithcustomview: LEFTBTN];

3. Adjust the position and set the left icon of the navigation bar

// adjust the position of Leftbarbuttonitem under IOS7

if([[[[[uidevicecurrentdevice] systemversion] Floatvalue]>=7.0? - : 0 ))

{

uibarbuttonitem *negativespacer = [[uibarbuttonitemalloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace

target:nilaction:Nil];

Negativespacer. width =------this value can be changed freely according to the situation

Self. Navigationitem. leftbarbuttonitems =@[negativespacer, Leftbarbuton];

}Else

self. Navigationitem. Leftbarbuttonitem = Leftbarbuton;



Solve the problem of customizing the left button of the navigation bar on the right after ios7.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.