在Interface Builder中,我有以下内容。
数字是虚拟的,因为我在构建单元格时覆盖了所有内容(如下所示为自定义类,content_view为self.contentView)。请注意,我没有实现sizeForItemAt,因为我只想使用VFL。
// Content View
let content_view_h = NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[content_view(avail_width@1000)]-0-|", options: NSLayoutConstraint.FormatOptions.alignAllTop, metrics: metrics, views: views as [String : Any])
NSLayoutConstraint.activate(content_view_h)
let content_view_v = NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[content_view(250@1000)]-0-|", options: NSLayoutConstraint.FormatOptions.alignAllTop, metrics: metrics, views: views as [String : Any])
NSLayoutConstraint.activate(content_view_v)
我不断得到以下信息,并且高度/宽度总是从Interface Builder中的数字中获取的... 250是我尝试穿过VFL的高度,而50是Interface Builder中的高度。
(
"<NSLayoutConstraint:0x6000005701e0 V:|-(0)-[UIView:0x7f8328caaf50] (active, names: '|':tictoc.ItemCVC:0x7f8328caacb0 )>",
"<NSLayoutConstraint:0x600000570230 UIView:0x7f8328caaf50.height == 250 (active)>",
"<NSLayoutConstraint:0x600000570280 V:[UIView:0x7f8328caaf50]-(0)-| (active, names: '|':tictoc.ItemCVC:0x7f8328caacb0 )>",
"<NSLayoutConstraint:0x600000571040 'UIView-Encapsulated-Layout-Height' tictoc.ItemCVC:0x7f8328caacb0.height == 50 (active)>"
)
如何停用在Interface Builder中硬编码的150宽50高度?有什么想法吗?