简体   繁体   English

无法将自定义IBDesignable类链接到情节提要上的UIButton

[英]Cannot link custom IBDesignable class to UIButton on storyboard

How do I connect IBDesignable custom class to UIButton? 如何将IBDesignable自定义类连接到UIButton?

Code

import UIKit

@IBDesignable class MyButton: UIView {
    @IBInspectable var borderColor: UIColor = UIColor.clear {
        didSet {
            layer.borderColor = borderColor.cgColor
        }
    }

    @IBInspectable var borderWidth: CGFloat = 0 {
        didSet {
            layer.borderWidth = borderWidth
        }
    }

    @IBInspectable var cornerRadius: CGFloat = 0 {
        didSet {
            layer.cornerRadius = cornerRadius
        }
    }
}

The name of the file is MyButton.swift 该文件的名称是MyButton.swift

在此处输入图片说明

It doesn't show MyButton as the class? 它没有显示MyButton作为类吗? How would I fix this problem? 我该如何解决这个问题?

您可能需要MyButton继承自UIButton,而不是UIView。

You can only link custom classes to objects of the same type, or a type it inherits from. 您只能将自定义类链接到相同类型或继承自其的类型的对象。 Instead of 代替

@IBDesignable class MyButton: UIView {

you probably want 你可能想要

@IBDesignable class MyButton: UIButton {

or link it to a UIView object instead 或将其链接到UIView对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 自定义UIButton @IBDesignable - Custom UIButton @IBDesignable 如何使用创建的自定义IBDesignable类从情节提要中更改按钮的cornerradius - How to change the cornerRadius of button from storyboard with custom IBDesignable class created 自定义@IBDesignable UIButton 崩溃 Xcode - Custom @IBDesignable UIButton crashes Xcode 尽管使用IBDesignable,但故事板中没有自定义UIStackView的预览 - No preview of custom UIStackView in Storyboard despite using IBDesignable 故事板中的自定义UIButton - Custom UIButton from storyboard UIButton的自定义类,并在具有枚举的StoryBoard中显示它 - Custom Class of UIButton and show it in StoryBoard having enum also iOS-无法获取@IBDesignable .xib文件以显示在情节提要或模拟器上 - iOS - Cannot get an @IBDesignable .xib file to show up on storyboard or simulator 快速将自定义@IBDesignable视图的故事板指南标题设置为@IBInspectable值? - Set the Storyboard guide title to a @IBInspectable value for a custom @IBDesignable view in swift? UIButton移到“自定义单元格”中的情节提要 - UIButton move to storyboard in Custom Cell 为什么此IBDesignable类不能在情节提要板上显示其更改? - Why does this IBDesignable class not display its changes on storyboard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM