简体   繁体   中英

Interface Builder cannot find intrinsicContentSize defined in a custom view

Interface Builder cannot find intrinsicContentSize of a custom view. For this given view code,

import Foundation
import UIKit

@IBDesignable
final class CustomView1: UIView {
    override var intrinsicContentSize: CGSize {
        return CGSize(width: 100, height: 100)
    }
}

I put a UIView instance and set its class to CustomView1 . It works at first, but if I close and re-open the storyboard, IB sometimes (not always) shows an error.

在此处输入图片说明

IB cannot find width of the view.

在此处输入图片说明

And this error disappears if I force Update Frames .

在此处输入图片说明

It looks like a bug. Or am I missing something important? What's your opinion? Any workaround?

Xcode 11 has intrinsic size option in Size inspector . as below

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM