Everything that I install dynamically can only be seen by running the application, but this is not very convenient, since I install the background to my View Controller and I also set the title for lable from the code. When I open the Storyboard I can not see anything ...

I know that there is such an annotation @IBDesignable which seems to solve this problem, but in my case, this is why it does not work ((

How to do?

Edit

Created a class

enter image description here

Added View on the screen visible hierarchy and inspection of this view

enter image description here

And so apply

 import UIKit class SplashViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() GradientView().backgroundColor = CustomColors().takeColor(color: .greyColor) } 

Does not want to show the background of the background (

Here is the result

enter image description here

    1 answer 1

    In this case, your mistake is what needs to be done for the element that needs to be changed. Those. UIView changes of background of UIView were visible, for UIView and it is necessary to write the corresponding class. An example of your past question:

     @IBDesignable class GradientView: UIView { @IBInspectable var gradientBackground: UIColor { set { let gradientLayer = CAGradientLayer() gradientLayer.frame = bounds gradientLayer.colors = [newValue.cgColor, UIColor.lightGray.cgColor, newValue.cgColor] gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5) gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5) UIGraphicsBeginImageContext(gradientLayer.bounds.size) gradientLayer.render(in: UIGraphicsGetCurrentContext()!) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() backgroundColor = UIColor(patternImage: image!) } get { return backgroundColor! } } } 

    And what it looks like in the interface builder: enter image description here

    • I understand that if you create a class for a view, then you need to add this custom view to the storyboard itself, right? I added it to the inspector and told her the GradientView class and in the ViewController method in the viewDidLoad() method viewDidLoad() performed the following line: GradientView().backgroundColor = CustomColors().takeColor(color: .greyColor) , but the background is not displayed either on the simulator or in a storyboard ... Don't understand what you did wrong? - Aleksey Timoshchenko
    • @AlekseyTimoshchenko Yes, they added a UIView , they ИмяСвоегоIBDesignableКласса it the ИмяСвоегоIBDesignableКласса . ViewController no longer associated with View here. To see the changes, add color in the variable setter (well, for the case in the example) gradientBackground . For example - in the interface of the builder, you can change the color of the Gradient Background and there will be a gradient of the выбранный цвет - серый - выбранный цвет - VAndrJ
    • Added an edit to the question, described everything with screenshots, where did he go wrong?) - Aleksey Timoshchenko
    • @AlekseyTimoshchenko try to change the color in the builder interface in the Gradient Background . Maybe the default does not cause set. - VAndrJ
    • If I understand correctly, the set will be called then when I try to assign a value to the variable gradientBackground, right? I assign it this value from SplashViewController here in this line GradientView().backgroundColor = CustomColors().takeColor(color: .greyColor) - Aleksey Timoshchenko