ios - 我们如何创建像复选标记一样的 IBInspectable?

标签 ios swift xcode ibdesignable ibinspectable

我创建了很多 IBInspectable。但是今天,我观察到 Xcode 具有这样的一些属性:

enter image description here

在链接中,我标记了矩形框。我想像这样创建自定义 IBInspectable 。我不知道这是否可能。

任何帮助将不胜感激。

最佳答案

按照以下步骤创建自定义 IBDesignable

第 1 步:

enter image description here

第 2 步:

enter image description here

第 3 步:将此代码添加到创建的 customTextView 文件中

import UIKit

@IBDesignable
class customTextView: UITextView {

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

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

@IBInspectable var borderColor: UIColor = UIColor.clear {
    didSet{
        layer.borderColor = borderColor.cgColor
    }
}

@IBInspectable var shadowOpacity: Float = 0 {
    didSet{
        layer.shadowOpacity = shadowOpacity
    }
}

@IBInspectable var shadowColor: UIColor = UIColor.clear {
    didSet{
        layer.shadowColor = shadowColor.cgColor
    }
}

@IBInspectable var shadowOffSet: CGSize = CGSize.zero {
    didSet{
        layer.shadowOffset = shadowOffSet
    }
}

}

第 4 步:

enter image description here

第 5 步:您可以在此处获取自定义字段

enter image description here

关于ios - 我们如何创建像复选标记一样的 IBInspectable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49323577/

相关文章:

ios - UISlider 扭曲圆角

ios - 触摸 SKShapeNode 不工作

ios - 我的应用程序由于未捕获的异常 'NSInvalidArgumentException' 而终止

iOS 应用程序只能支持一个 tabBar 项目的横向方向吗?

iphone - 如何在 iOS 中使用 Instrument

c++ - 如何在 XCode 中创建多个控制台窗口

ios - Swift - UICollectionReusableView 的 subview 不适合宽度

ios - 无法从今天的扩展程序中打开主机应用程序

ios - 如何从字典中提取数据

XCode 4 我可以将下载从一台机器复制到另一台机器吗