cdts/xdts-ios 3/TreeHole/Code/Gategory/UIBarButtonItem+PYExtension.m

48 lines
1.6 KiB
Mathematica
Raw Normal View History

2023-07-27 09:20:00 +08:00
//
// UIBarButtonItem+Extension.m
//
//
// Created by on 15/12/8.
// Copyright © 2015 iphone5solo. All rights reserved.
//
#import "UIBarButtonItem+PYExtension.h"
#import "UIView+PYExtension.h"
@implementation UIBarButtonItem (PYExtension)
+ (instancetype)py_itemWithViewController:(UIViewController *)viewController action:(SEL)action image:(NSString *)image highlightImage:(NSString *)highlightImage
{
UIButton *item = [UIButton buttonWithType:UIButtonTypeCustom];
//
[item setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
if (highlightImage.length > 0) {
[item setBackgroundImage:[UIImage imageNamed:highlightImage] forState:UIControlStateHighlighted];
}
//
[item addTarget:viewController action:action forControlEvents:UIControlEventTouchUpInside];
//
item.py_size = item.currentBackgroundImage.size;
return [[UIBarButtonItem alloc] initWithCustomView:item];
}
+ (instancetype)py_itemWithViewController:(UIViewController *)viewController action:(SEL)action title:(NSString *)title
{
UIButton *item = [UIButton buttonWithType:UIButtonTypeCustom];
//
[item setTitle:title forState:UIControlStateNormal];
//
item.titleLabel.font = [UIFont systemFontOfSize:16];
//
item.py_size = CGSizeMake(44, 44);
//
[item addTarget:viewController action:action forControlEvents:UIControlEventTouchUpInside];
return [[UIBarButtonItem alloc] initWithCustomView:item];
}
@end