Skip to content

Commit 601e9e9

Browse files
committed
Improved and finally fixed #37
The fields are now called sizeRatio and highlightedSizeRatio. The last one was missing, so the animation wasn't configurable at all.
1 parent e57abd9 commit 601e9e9

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/Components/MRStopButton.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,27 @@
1515
@interface MRStopButton : UIButton
1616

1717
/**
18-
Inset size ratio
18+
Size ratio in comparision to the parent view
19+
20+
The ratio by which the size of the click area will be resized in comparision to the parent size in default state.
21+
A positive value means that the stop button is smaller than the parent view.
22+
A negative value means that the stop button is bigger than the parent view.
23+
By default it has the value 0.3.
24+
25+
The method frameThatFits: will ensure that this property is applied. It has to be called by the parent view in the
26+
layoutSubviews by class contract.
27+
*/
28+
@property (nonatomic, assign) CGFloat sizeRatio;
29+
30+
/**
31+
Highlighted size ratio in comparision to the default state
1932
2033
The ratio by which the size of the click area will be resized, while touch is tracked inside.
2134
A positive value means that the stop button will be shrinked.
22-
A negative value means that the stop button will be enlagred.
23-
35+
A negative value means that the stop button will be enlarged.
36+
By default it has the value 0.9.
2437
*/
25-
@property (nonatomic, assign) CGFloat insetSizeRatio;
38+
@property (nonatomic, assign) CGFloat highlightedSizeRatio;
2639

2740
/**
2841
Asks the view to calculate and return the frame to be displayed in its parent.

src/Components/MRStopButton.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
3636
}
3737

3838
- (void)commonInit {
39-
self.insetSizeRatio = 0.35;
39+
self.sizeRatio = 0.3;
40+
self.highlightedSizeRatio = 0.9;
4041

4142
CAShapeLayer *shapeLayer = [CAShapeLayer new];
4243
[self.layer addSublayer:shapeLayer];
@@ -51,19 +52,19 @@ - (void)commonInit {
5152
- (CGRect)frameThatFits:(CGRect)parentBounds {
5253
CGFloat sizeValue = MIN(parentBounds.size.width, parentBounds.size.height);
5354
CGSize viewSize = CGSizeMake(sizeValue, sizeValue);
54-
const CGFloat sizeRatio = self.insetSizeRatio;
55+
const CGFloat insetSizeRatio = (1 - self.sizeRatio) / 2.0;
5556
return CGRectInset(MRCenterCGSizeInCGRect(viewSize, parentBounds),
56-
sizeValue * sizeRatio,
57-
sizeValue * sizeRatio);
57+
sizeValue * insetSizeRatio,
58+
sizeValue * insetSizeRatio);
5859
}
5960

6061
- (void)layoutSubviews {
6162
[super layoutSubviews];
6263

6364
CGRect frame = self.bounds;
6465

65-
if (self.tracking && self.touchInside) {
66-
const CGFloat insetSizeRatio = 0.033;
66+
if (self.tracking && self .touchInside) {
67+
const CGFloat insetSizeRatio = (1 - self.highlightedSizeRatio) / 2.0;
6768
frame = CGRectInset(frame,
6869
frame.size.width * insetSizeRatio,
6970
frame.size.height * insetSizeRatio);

0 commit comments

Comments
 (0)