【问题标题】:Storyboard UIView background color disappears when assigned @IBDesignable custom class分配 @IBDesignable 自定义类时,Storyboard UIView 背景颜色消失
【发布时间】:2016-02-04 02:51:40
【问题描述】:

重现步骤:

  1. 在下面创建类似MyIcon的类;

  2. 将 UIView 拖到故事板上(背景为白色);

  3. 设置UIView的自定义类为MyIcon;和

  4. 背景颜色消失。

MyIcon.swift:

import UIKit
@IBDesignable class MyIcon: UIView {}

请参阅下面的故事板屏幕截图,了解白色背景颜色丢失的证据:

【问题讨论】:

    标签: xcode swift uistoryboard xcode-storyboard ibdesignable


    【解决方案1】:

    可能是MyIcon 类中缺少一个init 函数。
    @IBDesignable 至少需要这两个函数:

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    

    为确保安全,您还可以查看 /Users/{yourusername}/Library/Logs/DiagnosticReports/ 中的崩溃报告

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-12
      • 1970-01-01
      • 2014-03-05
      • 2011-09-08
      • 1970-01-01
      • 2023-03-22
      相关资源
      最近更新 更多