Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anfriis
Copy link

@anfriis anfriis commented Oct 28, 2016

No description provided.

@anfriis anfriis mentioned this pull request Oct 28, 2016
@@ -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 }
Copy link
Owner

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

Copy link
Author

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? {
Copy link
Owner

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.

Copy link
Owner

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
        }
    }
}

Copy link
Author

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 ?

Copy link
Owner

@gontovnik gontovnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

@anfriis
Copy link
Author

anfriis commented Nov 7, 2016

I have made the changes now!



@IBInspectable
// Set a custom corner radius or use the default
Copy link
Owner

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 }
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants