[英]View debugging of UICollectionViewCell?
Is there a way to debug UI of custom UICollectionViewCell
in XCode? 有没有一种方法可以在XCode中调试自定义
UICollectionViewCell
UI? All I can see in the view debugging of the UICollectionView
is the cell being displayed as one solid UIView without any subviews, like this: 在
UICollectionView
的视图调试中,我所看到的就是将单元格显示为一个没有任何子视图的实体UIView,如下所示:
I would like to see all the subviews so I could easily debug UILabel
frames and so on. 我希望看到所有子视图,以便可以轻松调试
UILabel
框架等。 Thank you. 谢谢。
I had the same issue.. finally figured out this occurs when you add subviews directly to UICollectionViewCell
instead of adding subviews to it's contentView
. 我有同样的问题..最终发现,将子视图直接添加到
UICollectionViewCell
而不是将子视图添加到它的contentView
时会发生这种情况。
Example: 例:
This codes shows properly in the view debugger: 此代码在视图调试器中正确显示:
class Cell: UICollectionViewCell {
var fillView: UIView? {
didSet {
guard oldValue != fillView else {return}
oldValue?.removeFromSuperview()
if let fillView = fillView {
contentView.addSubview(fillView)
}
}
}
}
This does not show properly in the view debugger: 这在视图调试器中无法正确显示:
class Cell: UICollectionViewCell {
var fillView: UIView? {
didSet {
guard oldValue != fillView else {return}
oldValue?.removeFromSuperview()
if let fillView = fillView {
// Note: not adding to `contentView`
addSubview(fillView)
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.