简体   繁体   中英

How to see in the xib UI what is implemented in the code of custom view in Xcode?

I've implemented a custom UIView and have assigned this CustomUIView to the File's Owner , I outlet-ed a UIImageView in the CustomUIView as below

@IBOutlet weak var messageCardView: UIImageView!

And I've implemented init function:

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

    messageCardView.image = UIImage(named: "img_1")
    messageCardView.alpha = 0.5
}

I'd like the alpha attribute and image showing in my xib static file, is there any way to do that? Great thanks!

Just add @IBDesignable before your class declaration, like this:

@IBDesignable
public class CustomUIView : UIView {
    ...

It may not work until you save / reload your XIB, though.

More info: http://nshipster.com/ibinspectable-ibdesignable/#ibdesignable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM