iOS8中UITextField的默认borderColor是什么?

wmtdaxz3  于 2023-04-13  发布在  iOS
关注(0)|答案(7)|浏览(147)

我有一个带边框的按钮,我想将其样式设置为UITextField。
所以我试着:

self.dateButton.layer.borderColor = self.assesseeName.layer.borderColor

但这给了我一个黑色的边框:

如何获得与UITextField(屏幕截图顶部)相同的颜色?

3qpi33ja

3qpi33ja1#

我将按钮的边框颜色设置为标准的浅灰色,边框宽度设置为0.25,并与之匹配
雨燕3:

myButton.layer.borderWidth = 0.25
myButton.layer.borderColor = UIColor.lightGray.cgColor
am46iovg

am46iovg2#

可以使用以下代码将TextField的相同效果应用于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;
ndh0cuux

ndh0cuux3#

根据Mac的数字颜色表,边框的RGB是230,230,230。

xuo3flqw

xuo3flqw4#

在iOS 13中,颜色在亮和暗模式之间变化

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

o4hqfura5#

Swift 4 Answer

  • 文本域默认边框颜色为灰色。*
button.layer.borderColor = UIColor.gray.cgColor
button.layer.borderWidth = 0.15
iqxoj9l9

iqxoj9l96#

这对我很有效

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
yeotifhr

yeotifhr7#

这在Swift 5中对我很有效。

let borderColour = UIColor(red:204.0/255.0, green:204.0/255.0, blue:204.0/255.0, alpha:0.4)
dateButton.layer.borderColor = borderColour.cgColor
dateButton.layer.borderWidth = 1.0
dateButton.layer.cornerRadius = 5

相关问题