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;
根据 Mac 的数字色度计,边框的 RGB 为 230、230、230。
Swift 4 Answer
Textfield default border color is gray.
button.layer.borderColor = UIColor.gray.cgColor
button.layer.borderWidth = 0.15
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
}
This worked for me
let borderColor = UIColor(displayP3Red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 1.0)
uitextfield.borderColor = borderColor
uitextfield.borderWidth = 0.5
uitextfield.cornerRadius = 5
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.