-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for custom corner radius #35
base: master
Are you sure you want to change the base?
Conversation
@@ -13,7 +13,7 @@ import UIKit | |||
open class DGRunkeeperSwitchRoundedLayer: CALayer { | |||
|
|||
override open var bounds: CGRect { | |||
didSet { cornerRadius = bounds.height / 2.0 } | |||
didSet { cornerRadius = self.cornerRadius } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that this line is no longer needed. You can remove the whole override open var bounds: CGRect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have removed it
|
||
@IBInspectable | ||
// Set a custom corner radius or use the default | ||
open var customCornerRadius: CGFloat? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that you can call it cornerRadius
instead of customCornerRadius
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if a user wants cornerRadius
to be always rounded as it was previously and be able to resize the switch control?
The easiest way is to introduce new property open var rounded: Bool = false
.
If you do not want to create new var, then I suspect that you have to override bounds
and make calculations. An example:
override var bounds: CGRect {
didSet {
if cornerRadius == oldValue.height / 2.0 {
cornerRadius = bounds.height / 2.0
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I have renamed it to cornerRadius
.
I am not totally sure what you mean with the rounded
thing. If you don't set the cornerRadius
, it will be set to the default in finishInit()
. Then the user can specify 0, 8 or anything else to set the desired cornerRadius
. I guess that is fine ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments.
I have made the changes now! |
|
||
|
||
@IBInspectable | ||
// Set a custom corner radius or use the default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move comment above the @IBInspectable
// Set a custom corner radius or use the default | ||
open var cornerRadius: CGFloat? { | ||
didSet { | ||
guard let cornerRadius = self.cornerRadius else { return } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to not have corner radius optional
@@ -160,6 +167,9 @@ open class DGRunkeeperSwitch: UIControl { | |||
addGestureRecognizer(panGesture) | |||
|
|||
addObserver(self, forKeyPath: "selectedBackgroundView.frame", options: .new, context: nil) | |||
|
|||
// Set default corner radius | |||
cornerRadius = bounds.height / 2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we initialize it inline when declaring the variable?
@@ -65,6 +65,8 @@ class ViewController: UIViewController { | |||
runkeeperSwitch4.titleColor = .white | |||
runkeeperSwitch4.selectedTitleColor = UIColor(red: 135/255.0, green: 227/255.0, blue: 120/255.0, alpha: 1.0) | |||
runkeeperSwitch4.titleFont = UIFont(name: "HelveticaNeue-Light", size: 17.0) | |||
// Custom corner radius | |||
runkeeperSwitch4.cornerRadius = 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean that other 4 switchers won't have rounded corners?
No description provided.