@@ -28,7 +28,7 @@ - (instancetype)initWithFrame:(CGRect)frame
28
28
self.layer .cornerRadius = 2.0 ;
29
29
self.layer .borderWidth = 0.5 ;
30
30
31
- CGFloat splitX = CGRectGetWidth (frame) *11 /18 ;
31
+ CGFloat splitX = floor ( CGRectGetWidth (frame) *11 /18 ) ;
32
32
CGFloat frameHeight = CGRectGetHeight (frame);
33
33
CGFloat fontSize = 11 ;
34
34
if (kDevice_Is_iPhone6 ) {
@@ -37,8 +37,8 @@ - (instancetype)initWithFrame:(CGRect)frame
37
37
fontSize = 14 ;
38
38
}
39
39
40
- _lineView = [[UIView alloc ] initWithFrame: CGRectMake (splitX, frameHeight/ 3 , 0.5 , frameHeight/ 3 )];
41
- _lineView.backgroundColor = [UIColor colorWithHexString: @" 0xcacaca " ];
40
+ _lineView = [[UIView alloc ] initWithFrame: CGRectMake (splitX, 0 , 1 , frameHeight)];
41
+ _lineView.backgroundColor = [UIColor colorWithHexString: @" 0xf8f8f8 " ];
42
42
[self addSubview: _lineView];
43
43
44
44
_leftButton = [[UIButton alloc ] initWithFrame: CGRectMake (0 , 0 , splitX, frameHeight)];
@@ -58,7 +58,17 @@ - (instancetype)initWithFrame:(CGRect)frame
58
58
59
59
[self addSubview: _rightButton];
60
60
61
- _leftButton.enabled = _rightButton.enabled = NO ;
61
+ __weak typeof (self) weakSelf = self;
62
+ [_leftButton bk_addEventHandler: ^(id sender) {
63
+ if (weakSelf.buttonClickedBlock ) {
64
+ weakSelf.buttonClickedBlock (self, EaseGitButtonPositionLeft);
65
+ }
66
+ } forControlEvents: UIControlEventTouchUpInside];
67
+ [_rightButton bk_addEventHandler: ^(id sender) {
68
+ if (weakSelf.buttonClickedBlock ) {
69
+ weakSelf.buttonClickedBlock (self, EaseGitButtonPositionRight);
70
+ }
71
+ } forControlEvents: UIControlEventTouchUpInside];
62
72
63
73
_normalTitle = normalTitle;
64
74
_checkedTitle = checkedTitle? checkedTitle: normalTitle;
@@ -91,16 +101,17 @@ + (instancetype)gitButtonWithFrame:(CGRect)frame
91
101
92
102
+ (EaseGitButton *)gitButtonWithFrame : (CGRect )frame type : (EaseGitButtonType)type {
93
103
EaseGitButton *button;
104
+ UIColor *normalBGColor = [UIColor colorWithHexString: @" 0xDDDDDD" ];
94
105
switch (type) {
95
106
case EaseGitButtonTypeStar:
96
- button = [EaseGitButton gitButtonWithFrame: frame normalTitle: @" 收藏" checkedTitle: @" 已收藏" normalIcon: @" git_icon_star" checkedIcon: @" git_icon_stared" normalBGColor: nil checkedBGColor: [UIColor colorWithHexString: @" 0x3BBD79" ] normalBorderColor: [UIColor colorWithHexString: @" 0xB5B5B5 " ] checkedBorderColor: nil userNum: 0 checked: NO ];
107
+ button = [EaseGitButton gitButtonWithFrame: frame normalTitle: @" 收藏" checkedTitle: @" 已收藏" normalIcon: @" git_icon_star" checkedIcon: @" git_icon_stared" normalBGColor: normalBGColor checkedBGColor: [UIColor colorWithHexString: @" 0x3BBD79" ] normalBorderColor: nil checkedBorderColor: nil userNum: 0 checked: NO ];
97
108
break ;
98
109
case EaseGitButtonTypeWatch:
99
- button = [EaseGitButton gitButtonWithFrame: frame normalTitle: @" 关注" checkedTitle: @" 已关注" normalIcon: @" git_icon_watch" checkedIcon: @" git_icon_watched" normalBGColor: nil checkedBGColor: [UIColor colorWithHexString: @" 0x4E90BF" ] normalBorderColor: [UIColor colorWithHexString: @" 0xB5B5B5 " ] checkedBorderColor: nil userNum: 0 checked: NO ];
110
+ button = [EaseGitButton gitButtonWithFrame: frame normalTitle: @" 关注" checkedTitle: @" 已关注" normalIcon: @" git_icon_watch" checkedIcon: @" git_icon_watched" normalBGColor: normalBGColor checkedBGColor: [UIColor colorWithHexString: @" 0x4E90BF" ] normalBorderColor: nil checkedBorderColor: nil userNum: 0 checked: NO ];
100
111
break ;
101
112
case EaseGitButtonTypeFork:
102
113
default :
103
- button = [EaseGitButton gitButtonWithFrame: frame normalTitle: @" Fork" checkedTitle: @" Fork" normalIcon: @" git_icon_fork" checkedIcon: nil normalBGColor: nil checkedBGColor: nil normalBorderColor: [UIColor colorWithHexString: @" 0xB5B5B5 " ] checkedBorderColor: [UIColor colorWithHexString: @" 0xB5B5B5 " ] userNum: 0 checked: NO ];
114
+ button = [EaseGitButton gitButtonWithFrame: frame normalTitle: @" Fork" checkedTitle: @" Fork" normalIcon: @" git_icon_fork" checkedIcon: nil normalBGColor: normalBGColor checkedBGColor: normalBGColor normalBorderColor: nil checkedBorderColor: nil userNum: 0 checked: NO ];
104
115
break ;
105
116
}
106
117
button.type = type;
@@ -109,23 +120,27 @@ + (EaseGitButton *)gitButtonWithFrame:(CGRect)frame type:(EaseGitButtonType)type
109
120
110
121
- (void )updateContent {
111
122
if (_checked) {
112
- [_leftButton setTitle: _checkedTitle forState: UIControlStateNormal | UIControlStateDisabled ];
113
- [_leftButton setImage: [UIImage imageNamed: _checkedIcon] forState: UIControlStateNormal | UIControlStateDisabled ];
123
+ [_leftButton setTitle: _checkedTitle forState: UIControlStateNormal];
124
+ [_leftButton setImage: [UIImage imageNamed: _checkedIcon] forState: UIControlStateNormal];
114
125
115
126
self.backgroundColor = _checkedBGColor;
116
127
self.layer .borderColor = _checkedBorderColor.CGColor ;
117
128
}else {
118
- [_leftButton setTitle: _normalTitle forState: UIControlStateNormal | UIControlStateDisabled ];
119
- [_leftButton setImage: [UIImage imageNamed: _normalIcon] forState: UIControlStateNormal | UIControlStateDisabled ];
129
+ [_leftButton setTitle: _normalTitle forState: UIControlStateNormal];
130
+ [_leftButton setImage: [UIImage imageNamed: _normalIcon] forState: UIControlStateNormal];
120
131
121
132
self.backgroundColor = _normalBGColor;
122
133
self.layer .borderColor = _normalBorderColor.CGColor ;
123
-
134
+
135
+ }
136
+ UIColor *titleColor = [UIColor colorWithHexString: !_checked? @" 0x222222" : @" 0xffffff" ];
137
+ if (self.type == EaseGitButtonTypeFork) {
138
+ titleColor = [UIColor colorWithHexString: @" 0x222222" ];
124
139
}
125
- [_leftButton setTitleColor: [UIColor colorWithHexString: self .backgroundColor == [UIColor clearColor ]? @" 0x222222 " : @" 0xffffff " ] forState: UIControlStateNormal | UIControlStateDisabled ];
126
- [_rightButton setTitleColor: [UIColor colorWithHexString: self .backgroundColor == [UIColor clearColor ]? @" 0x222222 " : @" 0xffffff " ] forState: UIControlStateNormal | UIControlStateDisabled ];
140
+ [_leftButton setTitleColor: titleColor forState: UIControlStateNormal];
141
+ [_rightButton setTitleColor: titleColor forState: UIControlStateNormal];
127
142
128
- [_rightButton setTitle: [NSString stringWithFormat: @" %ld " , (long )_userNum] forState: UIControlStateNormal | UIControlStateDisabled ];
143
+ [_rightButton setTitle: [NSString stringWithFormat: @" %ld " , (long )_userNum] forState: UIControlStateNormal];
129
144
}
130
145
131
146
#pragma mark Set
0 commit comments