由于设备显示设置中的粗体文本选项,CAGradientLayer无法正常工作

时间:2018-07-05 13:01:42

标签: ios iphone swift ipad

如果我打开了显示和亮度设置中的粗体功能,则意味着CAGradientLayer不适用于图像。

    let btn = UIButton(type: .custom)
btn.frame = CGRect(x: 100, y: 100, width: #imageLiteral(resourceName: "White_Normal").size.width, height: #imageLiteral(resourceName: "White_Normal").size.height)
btn.setBackgroundImage(#imageLiteral(resourceName: "White_Normal").withRenderingMode(.alwaysTemplate), for: UIControlState.normal)
btn.setBackgroundImage(#imageLiteral(resourceName: "White_Active").withRenderingMode(.alwaysTemplate), for: UIControlState.highlighted)
btn.tintColor = UIColor.purple
let gradientLayer = CAGradientLayer()
gradientLayer.frame = btn.layer.bounds
gradientLayer.colors = [UIColor(white: 1.0, alpha: 1.0).cgColor, UIColor(white: 0.0, alpha: 1.0).cgColor]

gradientLayer.locations = [0.0, 0.5]
gradientLayer.cornerRadius = btn.layer.cornerRadius
btn.layer.mask = gradientLayer
print()
view.addSubview(btn)
let imageView = UIImageView(image: btn.backgroundImage(for: .normal))
imageView.frame = CGRect(x: 100, y: #imageLiteral(resourceName: "White_Normal").size.height+100, width: #imageLiteral(resourceName: "White_Normal").size.width, height: #imageLiteral(resourceName: "White_Normal").size.height)
view.addSubview(imageView)

enter image description here enter image description here

enter image description here

0 个答案:

没有答案