Closed king7532 closed 8 years ago
I found the problem, DGRunkeeperSwitchRoundedLayer
only sets the cornerRadius
on it's layer when the frame
property is set. However when using autolayout constraints on iOS, the frame
property is never set and therefore the cornerRadius
defaults to 0
. iOS autolayout constraints set the view's center
and bounds
properties instead of the frame
.
To make this work, I changed DGRunkeeperSwitchRoundedLayer
:
public class DGRunkeeperSwitchRoundedLayer: CALayer {
override public var cornerRadius: CGFloat {
get { return CGFloat(bounds.height / 2.0) }
set { super.cornerRadius = newValue }
}
}
See PR #18
Please check the latest commit and let me know if it works
Yes the latest master works for me. Thanks
Just curious why you decided to go with overriding bounds
instead of cornerRadius
?
I think it is just cleaner to update cornerRadius
on bounds
change instead of overriding cornerRadius
getter
In the example app, modify the
ViewController.swift
'srunkeeperSwitch2
to be laid out using autolayout programmatically, like:And this is what happens in the iOS simulator:
Do you have any idea why the border radius is not working using the above code?