iOS_工厂类

UIButton的处理

UIButton+BaseButton.h

// 快速BUtton生成
+ (UIButton * _Nullable)buttonWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont;
+ (UIButton * _Nullable)buttonWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius;
+ (UIButton * _Nullable)buttonWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius borderColor:(UIColor * _Nullable)borderColor borderWidth:(CGFloat)borderWidth;
+ (UIButton * _Nullable)buttonWithimage:(UIImage * _Nullable)image;
+ (UIButton * _Nullable)buttonWithimage:(UIImage * _Nullable)image bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius;
+ (UIButton * _Nullable)buttonWithimage:(UIImage * _Nullable)image bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius borderColor:(UIColor * _Nullable)borderColor borderWidth:(CGFloat)borderWidth;
+ (UIButton * _Nullable)buttonWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont image:(UIImage * _Nullable)image bgImage:(UIImage * _Nullable)bgImage bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius borderColor:(UIColor * _Nullable)borderColor borderWidth:(CGFloat)borderWidth;

+ (UIButton * _Nullable)buttonWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont {
    return [self buttonWithTitle:title titleColor:titleColor titleFont:titleFont image:nil bgImage:nil bgColor:nil cornerRadius:0 borderColor:nil borderWidth:0];
}
+ (UIButton * _Nullable)buttonWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius {
    return [self buttonWithTitle:title titleColor:titleColor titleFont:titleFont image:nil bgImage:nil bgColor:bgColor cornerRadius:cornerRadius borderColor:nil borderWidth:0];
}
+ (UIButton * _Nullable)buttonWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius borderColor:(UIColor * _Nullable)borderColor borderWidth:(CGFloat)borderWidth {
    return [self buttonWithTitle:title titleColor:titleColor titleFont:titleFont image:nil bgImage:nil bgColor:bgColor cornerRadius:cornerRadius borderColor:borderColor borderWidth:borderWidth];
}
+ (UIButton * _Nullable)buttonWithimage:(UIImage * _Nullable)image {
    return [self buttonWithTitle:nil titleColor:nil titleFont:nil image:image bgImage:nil bgColor:nil cornerRadius:0 borderColor:nil borderWidth:0];
}
+ (UIButton * _Nullable)buttonWithimage:(UIImage * _Nullable)image bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius {
    return [self buttonWithTitle:nil titleColor:nil titleFont:nil image:image bgImage:nil bgColor:bgColor cornerRadius:cornerRadius borderColor:nil borderWidth:0];
}
+ (UIButton * _Nullable)buttonWithimage:(UIImage * _Nullable)image bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius borderColor:(UIColor * _Nullable)borderColor borderWidth:(CGFloat)borderWidth {
    return [self buttonWithTitle:nil titleColor:nil titleFont:nil image:image bgImage:nil bgColor:bgColor cornerRadius:cornerRadius borderColor:borderColor borderWidth:borderWidth];
}
+ (UIButton * _Nullable)buttonWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont image:(UIImage * _Nullable)image bgImage:(UIImage * _Nullable)bgImage bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius borderColor:(UIColor * _Nullable)borderColor borderWidth:(CGFloat)borderWidth {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if (title) {
        [button setTitle:title forState:UIControlStateNormal];
    }
    if (titleColor) {
        [button setTitleColor:titleColor forState:UIControlStateNormal];
    }
    if (titleFont) {
        button.titleLabel.font = titleFont;
    }
    if (image) {
        [button setImage:image forState:UIControlStateNormal];
    }
    if (bgImage) {
        [button setBackgroundImage:bgImage forState:UIControlStateNormal];
    }
    if (bgColor) {
        [button setBackgroundColor:bgColor];
    }
    if (cornerRadius) {
        button.layer.cornerRadius = cornerRadius;
    }
    if (borderColor) {
        button.layer.borderColor = [borderColor CGColor];
    }
    if (borderWidth) {
        button.layer.borderWidth = borderWidth;
    }
    return button;
}

UILabel的处理

UILabel+BaseLabel.h

// 快速label生成
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont;
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont textAlignment:(NSTextAlignment)textAlignment;
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont numberOfLines:(NSInteger)numberOfLines;
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont textAlignment:(NSTextAlignment)textAlignment numberOfLines:(NSInteger)numberOfLine;

+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius;
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius textAlignment:(NSTextAlignment)textAlignment numberOfLines:(NSInteger)numberOfLines;
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius borderColor:(UIColor * _Nullable)borderColor borderWidth:(CGFloat)borderWidth textAlignment:(NSTextAlignment)textAlignment numberOfLines:(NSInteger)numberOfLines;
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont {
    return [self labelWithTitle:title titleColor:titleColor titleFont:titleFont bgColor:nil cornerRadius:0 borderColor:nil borderWidth:0 textAlignment:NSTextAlignmentNatural numberOfLines:1];
}
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont textAlignment:(NSTextAlignment)textAlignment {
    return [self labelWithTitle:title titleColor:titleColor titleFont:titleFont bgColor:nil cornerRadius:0 borderColor:nil borderWidth:0 textAlignment:textAlignment numberOfLines:1];
}
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont numberOfLines:(NSInteger)numberOfLines {
    return [self labelWithTitle:title titleColor:titleColor titleFont:titleFont bgColor:nil cornerRadius:0 borderColor:nil borderWidth:0 textAlignment:NSTextAlignmentNatural numberOfLines:numberOfLines];
}
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont textAlignment:(NSTextAlignment)textAlignment numberOfLines:(NSInteger)numberOfLine {
    return [self labelWithTitle:title titleColor:titleColor titleFont:titleFont bgColor:nil cornerRadius:0 borderColor:nil borderWidth:0 textAlignment:textAlignment numberOfLines:numberOfLine];
}

+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius {
    return [self labelWithTitle:title titleColor:titleColor titleFont:titleFont bgColor:bgColor cornerRadius:cornerRadius borderColor:nil borderWidth:0 textAlignment:NSTextAlignmentNatural numberOfLines:1];
}
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius textAlignment:(NSTextAlignment)textAlignment numberOfLines:(NSInteger)numberOfLines {
    return [self labelWithTitle:title titleColor:titleColor titleFont:titleFont bgColor:bgColor cornerRadius:cornerRadius borderColor:nil borderWidth:0 textAlignment:textAlignment numberOfLines:numberOfLines];
}
+ (UILabel *)labelWithTitle:(NSString * _Nullable)title titleColor:(UIColor * _Nullable)titleColor titleFont:(UIFont * _Nullable)titleFont bgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius borderColor:(UIColor * _Nullable)borderColor borderWidth:(CGFloat)borderWidth textAlignment:(NSTextAlignment)textAlignment numberOfLines:(NSInteger)numberOfLines {
    UILabel *label = [UILabel new];
    if (title) {
        label.text = title;
    }
    if (titleColor) {
        label.textColor = titleColor;
    }
    if (titleFont) {
        label.font = titleFont;
    }
    if (bgColor) {
        label.backgroundColor = bgColor;
    }
    if (cornerRadius) {
        label.layer.cornerRadius = cornerRadius;
    }
    if (borderColor) {
        label.layer.borderColor = [borderColor CGColor];
    }
    if (borderWidth) {
        label.layer.borderWidth = borderWidth;
    }
    if (textAlignment) {
        label.textAlignment = textAlignment;
    }
    if (numberOfLines) {
        label.numberOfLines = numberOfLines;
    }
    return label;
}

UIView的处理

UIView+BaseView.h

+ (UIView * _Nullable)viewWithBgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius;
+ (UIView * _Nullable)viewWithBgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius borderColor:(UIColor * _Nullable)borderColor borderWidth:(CGFloat)borderWidth;
+ (UIView * _Nullable)viewWithBgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius {
    return [self viewWithBgColor:bgColor cornerRadius:cornerRadius borderColor:nil borderWidth:0];
}
+ (UIView * _Nullable)viewWithBgColor:(UIColor * _Nullable)bgColor cornerRadius:(CGFloat)cornerRadius borderColor:(UIColor * _Nullable)borderColor borderWidth:(CGFloat)borderWidth {
    UIView *view = [UIView new];
    if (bgColor) {
        view.backgroundColor = bgColor;
    }
    if (cornerRadius) {
        view.layer.cornerRadius = cornerRadius;
    }
    if (borderColor) {
        view.layer.borderColor = [borderColor CGColor];
    }
    if (borderWidth) {
        view.layer.borderWidth = borderWidth;
    }
    return view;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值