OGeek|极客世界-中国程序员成长平台

标题: ios - Xcode 8 GM 破坏了我的 UI [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:35
标题: ios - Xcode 8 GM 破坏了我的 UI

啊。选择初始设备 View (6s)后,我所有的边界都完全搞砸了。我使用了以下代码:

func roundButtonLeft(button: UIButton) {

    let path = UIBezierPath(roundedRect:button.bounds, byRoundingCorners:[.topLeft, .bottomLeft], cornerRadii: CGSize(width: 10, height: 10))
    let maskLayer = CAShapeLayer()
    maskLayer.path = path.cgPath

    let frameLayer = CAShapeLayer()
    frameLayer.path = path.cgPath
    frameLayer.lineWidth = 1.0
    frameLayer.strokeColor = UIColor.white.cgColor
    frameLayer.fillColor = nil

    button.layer.addSublayer(frameLayer)
    button.layer.mask = maskLayer}

在我的 UI 按钮的一侧添加了边框。这现在根本不起作用,白色边框从屏幕上射出。

如果我放弃我的更改,它会在我打开 Storyboard 并被迫选择初始设备之前正常工作。

有人可以帮忙吗?我已经为此浪费了几个晚上。



Best Answer-推荐答案


这花了很长时间才弄清楚。但它与 button.bounds 有关。

我通过添加来修复它:

button.layoutIfNeeded()

在添加子层之前。

关于ios - Xcode 8 GM 破坏了我的 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39604641/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4