封装UIBarButtonItem
Posted iOS学习-文
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了封装UIBarButtonItem相关的知识,希望对你有一定的参考价值。
#import <UIKit/UIKit.h> @interface UIBarButtonItem (XMGExtension) + (instancetype)itemWithImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action; @end
#import "UIBarButtonItem+XMGExtension.h" @implementation UIBarButtonItem (XMGExtension) + (instancetype)itemWithImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal]; [button setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted]; button.size = button.currentBackgroundImage.size; [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; return [[self alloc] initWithCustomView:button]; } @end
以上是关于封装UIBarButtonItem的主要内容,如果未能解决你的问题,请参考以下文章
VSCode自定义代码片段14——Vue的axios网络请求封装
VSCode自定义代码片段14——Vue的axios网络请求封装