Skip to content

Commit 9b0d70f

Browse files
committed
experimental: Supports hover color.
1 parent 795882a commit 9b0d70f

File tree

7 files changed

+47
-5
lines changed

7 files changed

+47
-5
lines changed

MKAToggleButton.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "MKAToggleButton"
19-
s.version = "1.2.0"
19+
s.version = "1.2.3"
2020
s.summary = "MKAToggleButton is multiple icons toggle button for iOS."
2121

2222
# This description is used to generate tags and improve search results.

MKAToggleButton/Headers/MKAIconToggleButton.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ NS_ASSUME_NONNULL_BEGIN
9797
* The current state. The toggle button automatically increments the state each time it is clicked.
9898
*/
9999
@property (nonatomic) NSUInteger currentStateIndex;
100+
/**
101+
* A color when hovering. (iOS13+)
102+
*/
103+
@property (nonatomic, nullable) UIColor *hoverColor;
100104

101105
+ (instancetype)toggleButtonWithItems:(NSArray<MKAToggleItem *> *)items;
102106
+ (instancetype)toggleButtonWithItems:(NSArray<MKAToggleItem *> *)items

MKAToggleButton/Resources/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
<key>CFBundlePackageType</key>
1818
<string>FMWK</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.2.0</string>
20+
<string>1.2.3</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>4</string>
24+
<string>7</string>
2525
<key>NSHumanReadableCopyright</key>
2626
<string>Copyright Hituzi Ando. All rights reserved.</string>
2727
</dict>

MKAToggleButton/Sources/MKAIconToggleButton.m

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ - (CGSize)sizeWithFont:(UIFont *)font {
6666
@interface MKAIconToggleButton ()
6767

6868
@property (nonatomic, copy) NSMutableArray<MKAToggleItem *> *items;
69+
@property (nonatomic, nullable) UIColor *tintColorCache;
6970

7071
@end
7172

@@ -187,6 +188,11 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
187188

188189
#pragma mark - property
189190

191+
- (void)setTintColor:(UIColor *)color {
192+
[super setTintColor:color];
193+
self.tintColorCache = color;
194+
}
195+
190196
- (CGRect)touchableBounds {
191197
CGRect rect = self.bounds;
192198
rect.origin.x -= self.touchableExtensionLeft;
@@ -236,6 +242,14 @@ - (instancetype)build {
236242
}];
237243
self.bounds = (CGRect) { CGPointZero, CGSizeMake(maxSize.width + MKAIconToggleButtonMarginX, maxSize.height) };
238244

245+
self.tintColorCache = self.tintColor;
246+
247+
if (@available(iOS 13.0, *)) {
248+
UIHoverGestureRecognizer *recognizer = [[UIHoverGestureRecognizer alloc] initWithTarget:self
249+
action:@selector(hovering:)];
250+
[self addGestureRecognizer:recognizer];
251+
}
252+
239253
return self;
240254
}
241255

@@ -270,4 +284,24 @@ - (nullable NSString *)titleAtIndex:(NSUInteger)index {
270284
}
271285
}
272286

287+
- (void)hovering:(UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0)) {
288+
if (!self.hoverColor) {
289+
return;
290+
}
291+
292+
switch (recognizer.state) {
293+
case UIGestureRecognizerStateBegan:
294+
case UIGestureRecognizerStateChanged:
295+
self.tintColor = self.hoverColor;
296+
[self setTitleColor:self.tintColor forState:UIControlStateNormal];
297+
break;
298+
case UIGestureRecognizerStateEnded:
299+
self.tintColor = self.tintColorCache;
300+
[self setTitleColor:self.tintColor forState:UIControlStateNormal];
301+
break;
302+
default:
303+
break;
304+
}
305+
}
306+
273307
@end

Sample/Framework/MKAToggleButton.framework/Headers/MKAIconToggleButton.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ NS_ASSUME_NONNULL_BEGIN
9797
* The current state. The toggle button automatically increments the state each time it is clicked.
9898
*/
9999
@property (nonatomic) NSUInteger currentStateIndex;
100+
/**
101+
* A color when hovering. (iOS13+)
102+
*/
103+
@property (nonatomic, nullable) UIColor *hoverColor;
100104

101105
+ (instancetype)toggleButtonWithItems:(NSArray<MKAToggleItem *> *)items;
102106
+ (instancetype)toggleButtonWithItems:(NSArray<MKAToggleItem *> *)items
31.1 KB
Binary file not shown.

Sample/Framework/MKAToggleButton.framework/Resources/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
<key>CFBundlePackageType</key>
1818
<string>FMWK</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.2.0</string>
20+
<string>1.2.3</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>4</string>
24+
<string>7</string>
2525
<key>NSHumanReadableCopyright</key>
2626
<string>Copyright Hituzi Ando. All rights reserved.</string>
2727
</dict>

0 commit comments

Comments
 (0)