// UIBarButtonItem + LYExtension.h
// Created by YoungLee on **/**/**
// Copyright (c) **** YoungLee.All rights reserved.
#import <UIKit/UIKit.h>
@interface UIBarButtonItem(LYExtension)
+ (instancetype)itemWithImageName:(NSString *)imageName highLightImageName:(NSString *)highLightImageName target:(id)target action:(SEL)action;
@end
// UIBarButtonItem + LYExtension.m
// Created by YoungLee on **/**/**
// Copyright (c) **** YoungLee.All rights reserved.
#import "UIBarButtonItem + LYExtension.h"
@implementation UIBarButtonItem(LYExtension)
+ (instancetype)itemWithImageName:(NSString *)imageName highLightImageName:(NSString *)highLightImageName target:(id)target action:(SEL)action {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:highLightImageName] forState:UIControlStateHighLight];
button.size = button.currentBackgroundImage.size;
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return [[self alloc] initWithCustomView:button];
}
@end
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。