why the autolayout is not updated if I use IBDesignable file when i run the app?
The problem here is that you specify the frame height in setHeight(), but also specify the height with a layout constraint inside storyboard. One way to fix this is to specify an intrinsicContentSize for your view and not specify the height as a layout constraint in storyboard. (I.o.w. similar to the way you rely on the width of the label to be calculated for you)
@IBDesignable
class CustomParentNavigationBarView: UIView {
lazy var deviceHasTopNotch: Bool = {
if #available(iOS 11.0, tvOS 11.0, *) {
// with notch: 44.0 on iPhone X, XS, XS Max, XR.
// without notch: 20.0 on iPhone 8 on iOS 12+.
return UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0 > 20
}
return false
}()
override var intrinsicContentSize: CGSize {
let height:CGFloat = deviceHasTopNotch ? 88 : 64
let width = super.intrinsicContentSize.width //Use whatever you prefer here. Ex.UIScreen.main.bounds.size.width
return CGSize(width: width, height: height)
}
}
In Storyboard
Remove your current height constraint for the custom view. Set the Intrinsic Size
property to Placeholder
.
Example of the layout constraints for the custom nav bar.
@IBDesignable error: IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool crashed
There are crash reports generated when Interface Builder Cocoa Touch Tool crashes. Theses are located in ~/Library/Logs/DiagnosticReports
and named IBDesignablesAgentCocoaTouch_*.crash
. In my case they contained a useful stack-trace that identified the issue in my code.
IB Designables: Failed to render and update auto layout status ...The agent crashed
You asked:
Can someone suggest a method to overcome this crash in IBDesigner?
We can’t solve the named color problem, but we certainly can eliminate the crash by avoiding forced unwrapping operator, !
. E.g. you could use a nil
-coalescing operator, ??
, instead, so you have some fall-back color for IB, e.g.
backgroundColor = UIColor(named: "Color.Button.Background") ?? .blue
But, if you don’t force unwrap, it won’t crash. And while it won’t use your named color in IB, it will when you run the app.
Personally, I’d avoid setting any properties usually set in IB (such as backgroundColor
) in a designable view, itself. I think it’s exceedingly confusing to be looking at some view in IB, change a property, such as the background color, and not have it render correctly.
What can be configured in IB should probably be left in IB to avoid any confusion.
But let’s consider an example where I did want a custom color property to use a named color. I’d declare an @IBInspectable
color property, e.g., consider this circle view with a custom fillColor
:
@IBDesignable
class CircleView: UIView {
let shapeLayer = CAShapeLayer()
@IBInspectable var fillColor: UIColor = .blue { didSet { shapeLayer.fillColor = fillColor.cgColor } }
override init(frame: CGRect = .zero) {
super.init(frame: frame)
configure()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
configure()
}
override func layoutSubviews() {
super.layoutSubviews()
updatePaths()
}
}
private extension CircleView {
func configure() {
layer.addSublayer(shapeLayer)
shapeLayer.fillColor = fillColor.cgColor
}
func updatePaths() {
let center = CGPoint(x: bounds.midX, y: bounds.midY)
let radius = min(bounds.width, bounds.height) / 2
shapeLayer.path = UIBezierPath(arcCenter: center, radius: radius, startAngle: 0, endAngle: 2 * .pi, clockwise: true).cgPath
}
}
I’d then set the named color in IB attributes inspector:
The other approach, is to not use named colors in the asset catalog, but rather define your own UIColor
extension:
extension UIColor {
static let buttonBackground = #colorLiteral(red: 0, green: 1, blue: 1, alpha: 1)
}
Then when you want to set some color property, you can do something like:
backgroundColor = .buttonBackground
The downside of this approach is that you lose the ability to use the named color within IB for other controls. But it’s another pattern to consider.
Failed to render and update auto layout status, Failed to launch designables agent because tool was shutting down
Failed to render and update auto layout status for ReportsViewController
This error should not prevent you from building/running your application. It is often a Xcode bug, and most of the times you can get rid of it just by opening a .swift
file and returning to the storyboard
, undo & redoing last change or cleaning build folder.
No account for team "**********".
This must be the one stopping you from running your app, to fix it you must sign in with an Apple account. See here: https://stackoverflow.com/a/56774681/8125224
Xcode 8 - IB Designables - Failed to render and update auto layout status, The agent crashed
You can try one of the following to figure out the cause:
- look for the
IBDesignablesAgentCocoaTouch
logs in this directory:~/Library/Logs/DiagnosticReports
and see the cause.
Note: for user with Catalina: look for
IBDesignablesAgent-iOS_<DATE>-<MAC_NAME>.crash
Go to the Editor -> Debug Selected View while selecting your
@IBDesignable UIView
in your storyboard, and see the stack trace.Delete Derive Data folder.
Xcode Preference -> Location -> Derived Data
/Users/YourMacName/Library/Developer/Xcode/DerivedDataClean your project
Shift
+Command
+Alt
+K
.Build your project
Command
+B
.
Related Topics
How Is It I Can Animate the Change in Bar Tint Color of a Uinavigationbar But Not a Uitabbar
How to Unwrap the Elements of an Array in Swift? (Ie. Array<Int> as Array<Int>)
Uidropinteractiondelegate Performdrop Not Called
Apple Watch Table - First 4 Rows Not Appearing
Programmatically Set Uipageviewcontroller Transition Style to Scroll
How to Call Presentviewcontroller in Uiview Class
Two Uibezierpaths Intersection as a Uibezierpath
How to Use Po Command in Console (Debug Area)
How to Get Label Name from Button
How to Change Searchbar Border Color
Output Video Size Huge Using Hevc Encoder on iOS
How to Rotate a Scnsphere Using a Pan Gesture Recognizer
How to Check If Device Orientation Is Landscape Left or Right in Swift
User Notification Request Always Come with Default Action Identifier
Change Ncwidgetdisplaymode Programmatically in iOS10 Widget
How to Convert an Int into Nsdata in Swift
Swift 3 Nscache Generic Parameter 'Keytype' Could Not Be Inferred