// 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
网友评论