第一天08-UIBarButtonItem分类

2017-03-29  本文已影响0人  March_Cullen
// 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
上一篇下一篇

猜你喜欢

热点阅读