This is a memory problem. Label has no memory. Therefore, it returns 0 Instead of loading the nib into a custom class, you should load it into the ViewController. Replace gcCustomView with the following code.
gcCustomView.swift
import UIKit @IBDesignable class gcCustomView: UIView { @IBOutlet weak var titleLabel: UILabel! override func awakeFromNib() { super.awakeFromNib() // Initialization code if self.titleLabel != nil { self.titleLabel.text = "Default" } else { NSLog("Could not set title text as label.text was nil : was trying to set to default") } } @IBInspectable var cornerRadius: CGFloat = 0 { didSet { layer.cornerRadius = cornerRadius layer.masksToBounds = cornerRadius > 0 } } @IBInspectable var borderWidth: CGFloat = 0 { didSet { layer.borderWidth = borderWidth } } @IBInspectable var borderColor: UIColor? { didSet { layer.borderColor = borderColor?.cgColor } } override init(frame: CGRect) { super.init(frame: frame) // commitInit() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) // commitInit() } }
ViewController.swift
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad()
Then build. He will work.
source share