Extension of the Iosuibutton class, creating a Uibarbuttonitem button

Source: Internet
Author: User

. h file:

#import <UIKit/UIKit.h>@interface  uibarbuttonitem (yly)  /* * * Quickly create an item object (wrapping a button) * *  @param image   Button picture *  @param hilight Highlight *  @param target  button listener *  @param  The action button's lift callback method *  * */+ (Uibarbuttonitem *) Itemwithimage: (NSString *) Image Higlightedimage: (NSString *) hilight target: (ID) target action: (SEL) action; @end

. m Files:

#import "Uibarbuttonitem+yly.h"@implementationUibarbuttonitem (yly)+ (Uibarbuttonitem *) Itemwithimage: (NSString *) image higlightedimage: (NSString *) hilight target: (ID) Target action: (SEL) action{UIButton*BTN =[UIButton Buttonwithtype:uibuttontypecustom]; UIImage*normal =[UIImage Imagewithnamed:image];    [Btn Setbackgroundimage:normal Forstate:uicontrolstatenormal];    [Btn Setbackgroundimage:[uiimage imagewithnamed:hilight]forstate:uicontrolstatehighlighted]; Btn.bounds= CGRectMake (0,0, Normal.size.width, normal.size.height);    [Btn Addtarget:target action:action forcontrolevents:uicontroleventtouchupinside]; return[[Uibarbuttonitem alloc] initwithcustomview:btn];}@end

Use:

// Menu    Self.navigationItem.rightBarButtonItem = [Uibarbuttonitem itemwithimage:@ "navigationbar_pop  " higlightedimage:@"navigationbar_pop_highlighted" target:self action: @selector ( POP)];

Extension of the Iosuibutton class, creating a Uibarbuttonitem button

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.