|
@@ -0,0 +1,191 @@
|
|
|
|
|
+//
|
|
|
|
|
+// UIButton+Extersion.m
|
|
|
|
|
+// shiku_im
|
|
|
|
|
+//
|
|
|
|
|
+// Created by huangyp-pc on 2018/01/23.
|
|
|
|
|
+//
|
|
|
|
|
+
|
|
|
|
|
+#import "UIButton+Extersion.h"
|
|
|
|
|
+
|
|
|
|
|
+@implementation UIButton (Extersion)
|
|
|
|
|
+
|
|
|
|
|
++(UIButton *)sureButtonWithTitle:(NSString *)title{
|
|
|
|
|
+
|
|
|
|
|
+ UIButton *button = [UIButton new];
|
|
|
|
|
+
|
|
|
|
|
+ [button setTitle:title forState:UIControlStateNormal];
|
|
|
|
|
+ [button setTitle:title forState:UIControlStateHighlighted];
|
|
|
|
|
+ [button setTitleColor:HexColor(@"#FFFFFF") forState:UIControlStateNormal];
|
|
|
|
|
+ [button setTitleColor:HexColor(@"#FFFFFF") forState:UIControlStateHighlighted];
|
|
|
|
|
+ button.titleLabel.font = FONT_SIZE(18);
|
|
|
|
|
+
|
|
|
|
|
+ [button setBackgroundImage:[UIImage imageWithColor:HexColor(@"#8EB2CD")] forState:UIControlStateDisabled];
|
|
|
|
|
+ [button setBackgroundImage:[UIImage imageWithColor:HexColor(@"#2D84C0")] forState:UIControlStateHighlighted];
|
|
|
|
|
+ [button setBackgroundImage:[UIImage imageWithColor:HexColor(@"#33A2EE")] forState:UIControlStateNormal];
|
|
|
|
|
+
|
|
|
|
|
+ button.layer.cornerRadius = 5;
|
|
|
|
|
+ button.layer.masksToBounds = YES;
|
|
|
|
|
+
|
|
|
|
|
+ return button;
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (instancetype)initWithText:(NSString *)text fontSize:(CGFloat)size textColor:(UIColor *)color forState:(UIControlState)state
|
|
|
|
|
+{
|
|
|
|
|
+ self = [super init];
|
|
|
|
|
+ if (self) {
|
|
|
|
|
+ [self setTitle:text forState:state];
|
|
|
|
|
+ [self setTitleColor:color forState:state];
|
|
|
|
|
+ self.titleLabel.font = FONT_SIZE(size);
|
|
|
|
|
+ }
|
|
|
|
|
+ return self;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (instancetype)initWithAttributeString:(NSString *)string andImageName:(NSString *)imageName
|
|
|
|
|
+{
|
|
|
|
|
+ self = [super init];
|
|
|
|
|
+ if (self) {
|
|
|
|
|
+ NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] init];
|
|
|
|
|
+ NSTextAttachment *attach = [[NSTextAttachment alloc] init];
|
|
|
|
|
+ attach.image = [UIImage imageNamed:imageName];
|
|
|
|
|
+ attach.bounds = CGRectMake(0, -7, 25, 25);
|
|
|
|
|
+ NSAttributedString *attributeStr = [NSAttributedString attributedStringWithAttachment:attach];
|
|
|
|
|
+ [attributeString appendAttributedString:attributeStr];
|
|
|
|
|
+ NSAttributedString *titleString = [[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:FONT_SIZE(14),NSForegroundColorAttributeName:[UIColor whiteColor]}];
|
|
|
|
|
+ [attributeString appendAttributedString:titleString];
|
|
|
|
|
+ [self setAttributedTitle:attributeString forState:UIControlStateNormal];
|
|
|
|
|
+ }
|
|
|
|
|
+ return self;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (instancetype)initWithLevelAttributeString:(NSString *)string levelString:(NSString *)levelString imageName:(NSString *)imageName
|
|
|
|
|
+{
|
|
|
|
|
+ self = [super init];
|
|
|
|
|
+ if (self) {
|
|
|
|
|
+ self.titleLabel.numberOfLines = 3;
|
|
|
|
|
+ self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
+ NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] init];
|
|
|
|
|
+ NSTextAttachment *attach = [[NSTextAttachment alloc] init];
|
|
|
|
|
+ attach.image = [UIImage imageNamed:imageName];
|
|
|
|
|
+ attach.bounds = CGRectMake(0, -8, 25, 25);
|
|
|
|
|
+ NSAttributedString *attributeStr = [NSAttributedString attributedStringWithAttachment:attach];
|
|
|
|
|
+ [attributeString appendAttributedString:attributeStr];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *titleString = [[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:FONT_SIZE(15),NSForegroundColorAttributeName:RGB(235, 129, 16, 1.0)}];
|
|
|
|
|
+ [attributeString appendAttributedString:titleString];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *spaceString = [[NSAttributedString alloc] initWithString:@" \n" attributes:@{NSFontAttributeName:FONT_SIZE(8)}];
|
|
|
|
|
+ [attributeString appendAttributedString:spaceString];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *string = [[NSAttributedString alloc] initWithString:levelString attributes:@{NSFontAttributeName:FONT_SIZE(15),NSForegroundColorAttributeName:RGB(235, 129, 16, 1.0)}];
|
|
|
|
|
+ [attributeString appendAttributedString:string];
|
|
|
|
|
+
|
|
|
|
|
+ [self setAttributedTitle:attributeString forState:UIControlStateNormal];
|
|
|
|
|
+ }
|
|
|
|
|
+ return self;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (instancetype)initWithAttributeString:(NSString *)string andNameString:(NSString *)nameString andTextColor:(UIColor *)textColor
|
|
|
|
|
+{
|
|
|
|
|
+ self = [super init];
|
|
|
|
|
+ if (self) {
|
|
|
|
|
+ if (string && nameString) { // 只有当参数都有值的时候才创建富文本
|
|
|
|
|
+ self.titleLabel.numberOfLines = 2;
|
|
|
|
|
+ self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
+ NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] init];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *titleString = [[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:FONT_SIZE(18),NSForegroundColorAttributeName:textColor}];
|
|
|
|
|
+ [attributeString appendAttributedString:titleString];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *spaceString = [[NSAttributedString alloc] initWithString:@"\n" attributes:@{NSFontAttributeName:FONT_SIZE(16)}];
|
|
|
|
|
+ [attributeString appendAttributedString:spaceString];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *string = [[NSAttributedString alloc] initWithString:nameString attributes:@{NSFontAttributeName:FONT_SIZE(15),NSForegroundColorAttributeName:textColor}];
|
|
|
|
|
+ [attributeString appendAttributedString:string];
|
|
|
|
|
+
|
|
|
|
|
+ [self setAttributedTitle:attributeString forState:UIControlStateNormal];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return self;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (instancetype)initWithImageName:(NSString *)imageName andString:(NSString *)string textColor:(UIColor *)textColor
|
|
|
|
|
+{
|
|
|
|
|
+ self = [super init];
|
|
|
|
|
+ if (self) {
|
|
|
|
|
+ self.titleLabel.numberOfLines = 3;
|
|
|
|
|
+ self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
+ NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] init];
|
|
|
|
|
+ NSTextAttachment *attach = [[NSTextAttachment alloc] init];
|
|
|
|
|
+ attach.image = [UIImage imageNamed:imageName];
|
|
|
|
|
+ attach.bounds = CGRectMake(0, 0, 27, 27);
|
|
|
|
|
+ NSAttributedString *attributeStr = [NSAttributedString attributedStringWithAttachment:attach];
|
|
|
|
|
+ [attributeString appendAttributedString:attributeStr];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *spaceString = [[NSAttributedString alloc] initWithString:@"\n \n" attributes:@{NSFontAttributeName:FONT_SIZE(6)}];
|
|
|
|
|
+ [attributeString appendAttributedString:spaceString];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *titleString = [[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:FONT_SIZE(13),NSForegroundColorAttributeName:textColor}];
|
|
|
|
|
+ [attributeString appendAttributedString:titleString];
|
|
|
|
|
+ [self setAttributedTitle:attributeString forState:UIControlStateNormal];
|
|
|
|
|
+ }
|
|
|
|
|
+ return self;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (instancetype)initWithOriginalImage:(NSString *)imageName andString:(NSString *)string textColor:(UIColor *)textColor
|
|
|
|
|
+{
|
|
|
|
|
+ self = [super init];
|
|
|
|
|
+ if (self) {
|
|
|
|
|
+ self.titleLabel.numberOfLines = 2;
|
|
|
|
|
+ self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
+ NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] init];
|
|
|
|
|
+ NSTextAttachment *attach = [[NSTextAttachment alloc] init];
|
|
|
|
|
+ attach.image = [UIImage imageNamed:imageName];
|
|
|
|
|
+ attach.image = [UIImage imageNamed:imageName];
|
|
|
|
|
+ attach.bounds = CGRectMake(0, 0, 27, 27);
|
|
|
|
|
+ NSAttributedString *attributeStr = [NSAttributedString attributedStringWithAttachment:attach];
|
|
|
|
|
+ [attributeString appendAttributedString:attributeStr];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *spaceString = [[NSAttributedString alloc] initWithString:@"\n" attributes:@{NSFontAttributeName:FONT_SIZE(16)}];
|
|
|
|
|
+ [attributeString appendAttributedString:spaceString];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *titleString = [[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:FONT_SIZE(15),NSForegroundColorAttributeName:textColor}];
|
|
|
|
|
+ [attributeString appendAttributedString:titleString];
|
|
|
|
|
+ [self setAttributedTitle:attributeString forState:UIControlStateNormal];
|
|
|
|
|
+ }
|
|
|
|
|
+ return self;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+- (void)setImageName:(NSString *)imageName andString:(NSString *)string textColor:(UIColor *)textColor
|
|
|
|
|
+{
|
|
|
|
|
+ self.titleLabel.numberOfLines = 2;
|
|
|
|
|
+ self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
+ NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] init];
|
|
|
|
|
+ NSTextAttachment *attach = [[NSTextAttachment alloc] init];
|
|
|
|
|
+ attach.image = [UIImage imageNamed:imageName];
|
|
|
|
|
+ attach.bounds = CGRectMake(0, 0, 27, 27);
|
|
|
|
|
+ NSAttributedString *attributeStr = [NSAttributedString attributedStringWithAttachment:attach];
|
|
|
|
|
+ [attributeString appendAttributedString:attributeStr];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *spaceString = [[NSAttributedString alloc] initWithString:@"\n" attributes:@{NSFontAttributeName:FONT_SIZE(16)}];
|
|
|
|
|
+ [attributeString appendAttributedString:spaceString];
|
|
|
|
|
+
|
|
|
|
|
+ NSAttributedString *titleString = [[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:FONT_SIZE(13),NSForegroundColorAttributeName:textColor}];
|
|
|
|
|
+ [attributeString appendAttributedString:titleString];
|
|
|
|
|
+ [self setAttributedTitle:attributeString forState:UIControlStateNormal];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
++ (instancetype )ggButtonWithText:(NSString *)title fontSize:(CGFloat)size normalColor:(UIColor *)normalColor selectedColor:(UIColor *)selectedColor
|
|
|
|
|
+{
|
|
|
|
|
+ UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
|
+ [button setTitle:title forState:UIControlStateNormal];
|
|
|
|
|
+ button.titleLabel.font = FONT_SIZE(size);
|
|
|
|
|
+
|
|
|
|
|
+ [button setTitleColor:normalColor forState:UIControlStateNormal];
|
|
|
|
|
+ [button setTitleColor:selectedColor forState:UIControlStateSelected];
|
|
|
|
|
+
|
|
|
|
|
+ return button;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+@end
|