I recently updated both my Mac and Xcode version (now 11.6). When I open a large App I created I get 14 errors (Failed to render and update auto layout status for ..VC (code): The agent threw an excepetion) and about the same number of View Controllers have black backgrounds in the storyboard. The app runs fine in the simulator with the proper gradient backgrounds. The strange this is that as I go in and out of the storyboard, the errors start go away and the black backgrounds change to gradients. If I close the code and then reopen it, the 14 errors keep returning. Is there anyway to fix this?
StoryBoard View Backgrounds Black instead of gradient after updating Mac and Xcode
It turns out that the errors were related to a class setup for view with gradient background. The class which seems to be unstable in the current xcode was as follows:
import UIKit
@IBDesignable
class GradientView: UIView {
@IBInspectable var FirstColor: UIColor = UIColor.clear {
didSet{
updateView()
}}
@IBInspectable var SecondColor: UIColor = UIColor.clear {
didSet{
updateView()
}}
override class var layerClass: AnyClass {
get {
return CAGradientLayer.self
}
}
override func awakeFromNib() {
super.awakeFromNib()
self.layer.cornerRadius = 12
self.clipsToBounds = true
self.layer.borderWidth = 0.5 }
func updateView() {
let layer = self.layer as! CAGradientLayer
layer.colors = [FirstColor.cgColor, SecondColor.cgColor]
layer.startPoint = CGPoint(x:0.5,y:1.0)
layer.endPoint = CGPoint(x:0.5,y:0.0)
}
}
Using a different method for a gradient view class works fine. There seem to be many other issues with displaying storyboard graphics from the previous version of xcode, but none that produce errors, only lack of defintion of the view controllers... The gradient view class that worked is as follows:
class viewGradient: UIView {
override func awakeFromNib() {
super.awakeFromNib()
let gradientLayer = CAGradientLayer()
gradientLayer.frame = self.bounds
gradientLayer.colors = [UIColor.white.cgColor,UIColor.lightGray.cgColor,UIColor.systemTeal.cgColor]
self.layer.insertSublayer(gradientLayer, at: 0)
}
}
import UIKit
@IBDesignable
class GradientView: UIView {
@IBInspectable var FirstColor: UIColor = UIColor.clear {
didSet{
updateView()
}}
@IBInspectable var SecondColor: UIColor = UIColor.clear {
didSet{
updateView()
}}
override class var layerClass: AnyClass {
get {
return CAGradientLayer.self
}
}
override func awakeFromNib() {
super.awakeFromNib()
self.layer.cornerRadius = 12
self.clipsToBounds = true
self.layer.borderWidth = 0.5 }
func updateView() {
let layer = self.layer as! CAGradientLayer
layer.colors = [FirstColor.cgColor, SecondColor.cgColor]
layer.startPoint = CGPoint(x:0.5,y:1.0)
layer.endPoint = CGPoint(x:0.5,y:0.0)
}
}
Using a different method for a gradient view class works fine. There seem to be many other issues with displaying storyboard graphics from the previous version of xcode, but none that produce errors, only lack of defintion of the view controllers... The gradient view class that worked is as follows:
class viewGradient: UIView {
override func awakeFromNib() {
super.awakeFromNib()
let gradientLayer = CAGradientLayer()
gradientLayer.frame = self.bounds
gradientLayer.colors = [UIColor.white.cgColor,UIColor.lightGray.cgColor,UIColor.systemTeal.cgColor]
self.layer.insertSublayer(gradientLayer, at: 0)
}
}