Swift 4.2中自定义类UIButton的错误。 UIButton有什么新东西?

问题描述 投票:3回答:1

我有以下代码

import UIKit

class CustomButton: UIButton {

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        self.theme_setTitleColor(GlobalPicker.customButtonTextColor, forState: .normal)
        self.theme_setTitleColor(GlobalPicker.customButtonDisabledTextColor, forState: .disabled)
        self.theme_backgroundColor = GlobalPicker.primaryColor

        self.layer.cornerRadius = self.frame.height/4.0
        self.clipsToBounds = true

    }

    override init(frame: CGRect) {
        super.init(frame: frame)

        self.layer.cornerRadius = self.frame.height/2.0
        self.clipsToBounds = true
    }
}

当我尝试使用Xcode 10构建此代码时,我遇到了错误。代码在Xcode 9和Swift 4.0中运行良好。我希望无缝过渡,但显然这不是我得到的。

enter image description here

这是一个Xcode 10错误吗?其他人遇到类似的东西吗?

ios swift xcode uibutton swift4.2
1个回答
1
投票

我的猜测是,在你的项目或工作区的某个目标中某处有一个extension,它与UIButton混淆的方式会以某种方式削弱它。 (这是可能的事实是明确的,我认为它是一个错误;请参阅https://bugs.swift.org/browse/SR-2935和相关的重复项,包括https://bugs.swift.org/browse/SR-3228,以及我的https://bugs.swift.org/browse/SR-8010。)

您可以通过继承UIKit.UIButton而不是简单的UIButton来扩展扩展。由于这个原因,请参阅我的重复错误报告中的评论讨论。当扩展以这种方式运行时,它会重载方法,并且您可以通过使用模块命名空间来区分没有重载的UIButton。

© www.soinside.com 2019 - 2024. All rights reserved.