美文网首页
第一天08-UIBarButtonItem分类

第一天08-UIBarButtonItem分类

作者: March_Cullen | 来源:发表于2017-03-29 10:16 被阅读0次
    // 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
    

    相关文章

      网友评论

          本文标题:第一天08-UIBarButtonItem分类

          本文链接:https://www.haomeiwen.com/subject/scleottx.html