I have a very simple subclass of UITextView that adds the "Placeholder" functionality that you can find native to the Text Field object. Here is my code for the su
Make sure that you are not directly initialising UIImage
or UIFont
using assets or fonts added in your project.
I always create a private func setUp()
in my @IBDesignable
custom UI
classes.
which is called from init(frame: CGRect)
, init?(coder aDecoder: NSCoder)
. So I finally updated the setup()
as the following.
private func setUp() {
//... Doing initial configurations
// iconImageView.image = UIImage(named: "IconImageName")! // Causing the Crash, use if let OR guard let instead
if let icon = UIImage(named: "IconImageName") {
iconImageView.image = icon
iconImageView.frame.size = icon.size
}
// nameLabel.font = UIFont(name: "Calibri-Light", size: 15.0) // Causing the Crash, use if let OR guard let instead
if let font = UIFont(name: "Calibri-Light", size: size) {
nameLabel.font = font
} else {
nameLabel.font = UIFont.systemFont(ofSize: size)
}
// Doing other stuffs
}