I'm using storyboards for the first time in iOS 8 and so far have been loving the live rendering aspect of things on the storyboard. However, I seem to have hit a snag in getting my views to render properly on the storyboard.
I have a container UIView
that contains a connection to a UILabel
on the storyboard, I am attempting to set the label's text based on an IBInspectable
attribute on the label's parent container view.
@IBDesignable class ContainerView : UIView {
@IBOutlet weak var : titleLabel : UILabel!
@IBInspectable var title : String = "" {
didSet {
titleLabel?.text = title
}
}
/* Init functions */
prepareForInterfaceBuilder() {
self.titleLabel?.text = title
}
}
If I set the attribute in the storyboard it renders as expected while the program is executing but fails to render in the storyboard as I would expect. I've checked my connections and everything appears to be hooked up properly.
My question is: Is it possible to affect the contents of an IBOutlet connected view via IBInspectable attributes and have them live render on the storyboard, and if so, what am I missing or doing wrong?
Unfortunately you can't see IBOutlet
objects in interface builder for your custom views which are marked as IBDesignable
. If you want to see your outlets in interface builder, you have to use regular variables instead IBOutlet
and you have to create your objects programmatically.
Also please note that, if you need to change something from interface builder for your objects, you have to define your properties as IBInspectable
. Currently following variables types are valid for IBInspectable
:
Bool
, CGFloat
, CGPoint
, CGRect
, CGSize
, NSInteger
, NSString
, UIColor
, UIImage
I hope this answer is adequately clear for you.
Edit: I found following article which is describing a way how to do what you need:
http://justabeech.com/2014/07/27/xcode-6-live-rendering-from-nib/
2nd Edit: I tried the article and it works. Now I can see my outlets on interface builder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With