添加到main.storyboard后,XIB中的背景颜色消失

时间:2016-01-22 13:37:39

标签: ios xcode swift uiview xib

我创建了一个widget.xib,我有自己的观点,我想添加到main.storyboard。类widget.swift看起来像这样:

import UIKit

@IBDesignable class Widget: UIView {

var view: UIView!

var nibName: String = "Widget"

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

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

func setup(){

    view = loadViewFromNib()
    view.frame = bounds
    view.autoresizingMask = UIViewAutoresizing.FlexibleWidth
    view.autoresizingMask = UIViewAutoresizing.FlexibleHeight
    addSubview(view)    
}


func loadViewFromNib() -> UIView {

    let bundle = NSBundle(forClass: self.dynamicType)
    let nib = UINib(nibName: nibName, bundle: bundle)
    let view = nib.instantiateWithOwner(self, options: nil).first as! UIView

    return view
}
} //end class

我的小部件视图看起来像这样:

Xib File

现在,当我打开main.storyboard时,我会在这个故事板上添加视图,然后在这个新视图中我将课程设置为Widget我看到了所有标签,按钮但我没有'看到背景颜色。为什么? 快速查看我的main.storyboard:

Storyboard

0 个答案:

没有答案