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;
}