ios - 使用图层更改 UIButton 边框颜色

标签 ios swift uibutton cashapelayer cgcolor

我有一个 UIButton,我在 UILabel 的顶部和底部放置了一个边框。在更改线条颜色的同时,我在下面将线条设置为白色。我可以使用 UIColor.green.cgColor 将线条更改为预定颜色,例如绿色。 问题是我想将颜色设置为 topBorder.strokeColor = UIColor.init(red: 50, green: 50, blue: 50, alpha: 0.5).cgColor

当我这样做时,颜色仍然是白色的。为什么会这样?我可以将它设置为预定颜色,但它可以将它设置为我想要的特定颜色。

let topBorderTerms = CAShapeLayer()
let topPathTerms = UIBezierPath()
topPathTerms.move(to: CGPoint(x: 0, y: 0))
topPathTerms.addLine(to: CGPoint(x: Terms.frame.width, y: 0))
topBorderTerms.path = topPath.cgPath
topBorderTerms.strokeColor = UIColor.white.cgColor
topBorderTerms.lineWidth = 1.0
topBorderTerms.fillColor = UIColor.white.cgColor
Terms.layer.addSublayer(topBorderTerms)

enter image description here

最佳答案

替换

topBorder.strokeColor = UIColor.init(red: 50, green: 50, blue: 50, alpha: 0.5).cgColor. 

topBorder.strokeColor = UIColor(red: 50/255, green: 50/255, blue: 50/255, alpha: 0.5).cgColor

你错过了除以 255

关于ios - 使用图层更改 UIButton 边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58802631/

相关文章:

iphone - BluetoothManager 框架通知列表

ios - iOS UIButton 背景边框问题

ios - 在 UITextview 中定位 UIButton

iphone - UIImagePickerController 给我一个黑色预览

ios - iOS模拟器的 'color offscreen-rendered'功能有问题吗?

ios - 如何从 URLSession 获取数组

ios - 提供的 APNs 证书与当前环境不匹配

swift - 如何快速检查符合协议(protocol)的实例类?

ios - 使用 IOS9 时,无法在 UITable 节标题上的 UIButtons 上触发触摸事件(IOS10 没问题)

ios - 有没有一种有效的方法可以快速地将 float 舍入到最近的百分之一位置?