封装UIButton
#import <UIKit/UIKit.h>
@interface UIButton (Creat)
-(UIButton *)creatButtonWithFrame:(CGRect)frame backGround:(UIColor *)color title:(NSString *)title target:(id)target action:(SEL)action;
//SEL修饰方法类型,代表此参数是个方法
@end
#import "UIButton+Creat.h"
@implementation UIButton (Creat)
-(UIButton *)creatButtonWithFrame:(CGRect)frame backGround:(UIColor *)color title:(NSString *)title target:(id)target action:(SEL)action
{
UIButton *button = [[UIButton alloc]initWithFrame:frame];
button.backgroundColor = color;
[button setTitle:title forState:(UIControlStateNormal)];
[button setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return button;
}
@end
封装UILable
#import <UIKit/UIKit.h>
@interface UILabel (Creat)
-(UILabel *)createLableWithFrame:(CGRect)cg andFont:(CGFloat)font andTextalignment:(NSInteger)alignment andTextColor:(UIColor *)color andText:(NSString *)text;
@end
#import "UILabel+Creat.h"
@implementation UILabel (Creat)
-(UILabel *)createLableWithFrame:(CGRect)cg andFont:(CGFloat)font andTextalignment:(NSInteger)alignment andTextColor:(UIColor *)color andText:(NSString *)text
{
UILabel *lable = [[UILabel alloc]init];
lable.frame = cg;
lable.font = [UIFont systemFontOfSize:font];
lable.userInteractionEnabled = YES;
lable.textAlignment = alignment;
lable.textColor = color;
lable.text = text;
return lable;
}
@end
封装UIImageView
#import <UIKit/UIKit.h>
@interface UIImageView (Creat)
-(UIImageView *)creatImageViewWithFrame:(CGRect)cg andImageName:(NSString *)name;
@end
#import "UIImageView+Creat.h"
@implementation UIImageView (Creat)
-(UIImageView *)creatImageViewWithFrame:(CGRect)cg andImageName:(NSString *)name
{
UIImageView *imageView = [[UIImageView alloc]initWithFrame:cg];
imageView.userInteractionEnabled = YES;
imageView.image = [UIImage imageNamed:name];
return imageView;
}
@end
封装UIAlertController
#import <UIKit/UIKit.h>
@interface UIAlertController (Creat)
-(void)alertWithTitle:(NSString *)title message:(NSString *)message buttonTitle:(NSArray *)buttonTitle confirm:(void(^)(void))ok cancel:(void(^)(void))cancel inController:(UIViewController *)controller;
@end
#import "UIAlertController+Creat.h"
@implementation UIAlertController (Creat)
-(void)alertWithTitle:(NSString *)title message:(NSString *)message buttonTitle:(NSArray *)buttonTitle confirm:(void(^)(void))ok cancel:(void(^)(void))cancel inController:(UIViewController *)controller
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:(UIAlertControllerStyleAlert)];
NSString *str = buttonTitle[0];
UIAlertAction *action = [UIAlertAction actionWithTitle:str style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
if (ok) {
ok();//处理
}
}];
[alertController addAction:action];
str = buttonTitle[1];
action = [UIAlertAction actionWithTitle:str style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
if (cancel) {
cancel();//处理
}
}];
[alertController addAction:action];
[controller presentViewController:alertController animated:YES completion:nil];
}
@end