IBDesignable quick view not showing in storyboard

I want to configure a 5-star UIView, I also want it to appear in the storyboard. So I decided to use @IBDesignable and @ IBInspectable.The following is my code.

import UIKit @IBDesignable class RatingView: UIView { override init(frame: CGRect) { super.init(frame: frame) setUpView() } required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setUpView() } func setUpView() { let imageView = UIImageView(frame:CGRectMake(0, 0, 50,50)) imageView.image = UIImage(named: "star") addSubview(imageView) } } 

And then in my storyboard, I pulled a UIView into my canvas and set the Custom class for my custom view as RatingView. The compiler starts compiling the storyboard file, and I'm just waiting for the custom view to be displayed in canvas. Here is a screenshot. enter image description here

The status is "updated", but the view has not been rendered. The view simply remains white, I want to see the image that I add to the parent view. When I use UILabel instead of UIImageView, the label is renderd on the canvas, but not UIImageView, how can I display my beautiful star image on my canvas. (Images.xcassets has a star.png file)

enter image description here

use UILabel instead of UIImageView

 func setUpView() { let label = UILabel(frame: CGRectMake(0, 0, 50, 50)) label.text = "text" addSubview(label) } 

Result: enter image description here

+5
source share
1 answer

I tried to do the same. You must put the view in a frame. As @Benson Tommy said in the comments, look at the 411 WWDC 2014 session.

Here is the link to the session: https://developer.apple.com/videos/wwdc/2014/#411

Here is a link to the session transcript: http://asciiwwdc.com/2014/sessions/411

+1
source

Source: https://habr.com/ru/post/1206340/


All Articles