I have a button with a border that I want to style as a UITextField.
So I tried:
self.dateButton.layer.borderColor = self.assesseeName.layer.borderColor
But that gives me a black border:
How do I get the same color as the UITextField (top of screenshot)?
I set the border color for the button to be the standard light gray and the border width to be 0.25 and that matched
Swift 3:
myButton.layer.borderWidth = 0.25
myButton.layer.borderColor = UIColor.lightGray.cgColor
You can use the following code to apply same effect of textfield to buttton (borderwidth, bordercolor, & corner radius)
UIColor *borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0];
dateButton.layer.borderColor = borderColor.CGColor;
dateButton.layer.borderWidth = 1.0;
dateButton.layer.cornerRadius = 5.0;
According to the Mac's Digital Color Meter the RGB of the borders is 230, 230, 230.
In iOS 13 the color changes between light and dark mode
if #available(iOS 13.0, *) {
view.layer.borderColor = UIColor(dynamicProvider: { trait in
if trait.userInterfaceStyle == .light {
return UIColor(white: 0, alpha: 0.2)
} else {
return UIColor(white: 1, alpha: 0.2)
}
}).cgColor
} else {
view.layer.borderColor = UIColor(white: 0, alpha: 0.2).cgColor
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With