IOS7 UI compatible navigation bar button margins

Source: Internet
Author: User

The UI before IOS7 is:

In IOS7, for design reasons, the UI becomes:

The modified method overrides Uinavigationitem 's setleftbarbuttonitem and Setrightbarbuttonitem methods to make it compatible with previous versions;

The code is as follows:

@interface Uinavigationitem (margin) @end
@implementationUinavigationitem (margin)#if__iphone_os_version_max_allowed > __iphone_6_1-(void) Setleftbarbuttonitem: (Uibarbuttonitem *) _leftbarbuttonitem{if([[[[Uidevice Currentdevice] systemversion] Floatvalue] >=7.0) {Uibarbuttonitem*negativeseperator =[[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace target:nil Action:nil]; Negativeseperator.width= - A; if(_leftbarbuttonitem) {[Self setleftbarbuttonitems:@[negativeseperator, _leftbarbuttonitem]]; }        Else{[self setleftbarbuttonitems:@[negativeseperator]];    } [Negativeseperator release]; }    Else{[self setleftbarbuttonitem:_leftbarbuttonitem animated:no]; }}- (void) Setrightbarbuttonitem: (Uibarbuttonitem *) _rightbarbuttonitem{if([[[[Uidevice Currentdevice] systemversion] Floatvalue] >=7.0) {Uibarbuttonitem*negativeseperator =[[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace target:nil Action:nil]; Negativeseperator.width= - A; if(_rightbarbuttonitem) {[Self setrightbarbuttonitems:@[negativeseperator, _rightbarbuttonitem]]; }        Else{[self setrightbarbuttonitems:@[negativeseperator]];    } [Negativeseperator release]; }    Else{[self setrightbarbuttonitem:_rightbarbuttonitem animated:no]; }}#endif@end

Project source code does not make any changes, problem solving;

To add a button:

Uibarbuttonitem *leftbaritem == leftbaritem;[ Leftbaritem release];

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.