oc之UINavgationItemBar的分类

@interface UIButton (CBNavgationItem)

 

+ (UIButton *)cb_buttonWith:(UIButtonType)buttonType;

- (void)cbSet_Enable:(BOOL)isEnable;

@end

 

#import "UIButton+CBNavgationItem.h"

 

@implementation UIButton (CBNavgationItem)

 

+ (UIButton *)cb_buttonWith:(UIButtonType)buttonType{

    UIButton *button = [self buttonWithType:buttonType];

    [button.titleLabel setFont: Font_Nav_Item];

    return button;

}

- (void)cbSet_Enable:(BOOL)isEnable{

    if (isEnable) {

        self.enabled = YES;

        self.alpha = 1;

    }else{

        self.enabled = NO;

        self.alpha = 0.4;

    }

}

@end

 

 

 

 

@interface UIBarButtonItem (CBNavBarItem)

+ (UIBarButtonItem *)cb_BarButtonItemWithStyle:(UIBarButtonItemStyle)barButtonItemStyle Title:(NSString *)title action:(SEL)sel Target:(id)target;

- (void)cbSet_Enable:(BOOL)isEnable;

@end

#import "UIBarButtonItem+CBNavBarItem.h"

#import "UIImage+CBImage.h"

@implementation UIBarButtonItem (CBNavBarItem)

+ (UIBarButtonItem *)cb_BarButtonItemWithStyle:(UIBarButtonItemStyle)barButtonItemStyle Title:(NSString *)title action:(SEL)sel Target:(id)target{

    UIBarButtonItem *barItem = [[self alloc] initWithTitle:title style:barButtonItemStyle target:target action:sel];

    [barItem  setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont systemFontOfSize:16]} forState:UIControlStateNormal];

    return barItem;

}

- (void)cbSet_Enable:(BOOL)isEnable{

    if (isEnable) {

        self.enabled = YES;

        [self setBackgroundImage:[UIImage cb_ImageRectWithColor:[APPColor colorWithAlphaComponent:1]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

        [self setTintColor:[[UIColor whiteColor] colorWithAlphaComponent:1]];

    }else{

        self.enabled = NO;

        [self setBackgroundImage:[UIImage cb_ImageRectWithColor:[APPColor colorWithAlphaComponent:0.2]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

        [self setTintColor:[[UIColor whiteColor] colorWithAlphaComponent:1]];

    }

}

@end

 

posted @ 2019-01-25 10:04  sundaysios  阅读(87)  评论(0编辑  收藏  举报