swift - 无法在 Swift 的初始化程序中设置 UIButton buttonType

标签 swift

我想在 Swift 中子类化一个 UIButton。设置 buttonType

时出现错误
class MyButton: UIButton {

    init(label: KeyLabelType) {

        super.init(frame: CGRectZero)

        self.buttonType = UIButtonType.Custom
    }
}

关于为什么这是不正确的任何建议?

最佳答案

Apple 文档说 buttonType 是一个只读属性。您将必须为此找到解决方法。 This answer可能会给你你正在寻找的东西。

关于swift - 无法在 Swift 的初始化程序中设置 UIButton buttonType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24106841/

相关文章:

types - 定义对类型而非值进行操作的 Swift 函数

ios - 使用 AVAudioPlayer 播放声音

ios - 如何在 swift 中使用 xib 子类化自定义 Cell 类

swift - ARKit/RealityKit – People Occlusion 配置不工作

swift - 在 SwiftUI 文本中显示已发布的整数

swift - 如何在 Swift 2.0 中将 HKQuanity 转换为 Int

ios - 将 SKCameraNode 用于通用应用程序 SWIFT

swift - 为什么 Swift 访问修饰符默认不是私有(private)的?

ios - UIWebView 缓存不工作

Swift - 内部有后台线程的退出函数