我在让 PureLayout 与UILabel
's 一起工作时遇到了一些麻烦,我将它们放在我的视图中并试图彼此分开
我有一个标签,它与视图顶部和视图左侧有一定的间距。然后我有一个辅助标签,它也应该放置在视图左侧的一些边距处,然后从第一个标签的底部隔开相同数量的边距
theautoPinEdge
似乎想UIView
引用边界,而 aUILabel
显然不是 aUIView
所以我试图弄清楚如何让它工作
我的第一个想法是创建新视图来保存标签,这样我就可以引用视图来获取坐标等,但它们现在没有出现在视图中,这是基本设置
placeTitleLabelView = UIView(frame: CGRect.zero)
placeTitleLabel = UILabel(frame: CGRect.zero)
placeTitleLabel.textColor = UIColor.white
placeTitleLabel.font = UIFont(name: "Helvetica", size: 25)
placeTitleLabelView.addSubview(placeTitleLabel)
scrollView.addSubview(placeTitleLabelView)
placeDistanceLabelView = UIView(frame: CGRect.zero)
placeDistanceLabel = UILabel(frame: CGRect.zero)
placeDistanceLabel.textColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.5)
placeDistanceLabel.font = UIFont(name: "Helvetica", size: 18)
placeDistanceLabelView.addSubview(placeDistanceLabel)
scrollView.addSubview(placeDistanceLabelView)
然后我尝试设置所有约束
placeTitleLabelView.autoPinEdge(.left, to: .left, of: scrollView, withOffset: edgesInset)
placeTitleLabelView.autoPinEdge(.top, to: .top, of: scrollView, withOffset: edgesInset)
placeDistanceLabelView.autoPinEdge(.left, to: .left, of: scrollView, withOffset: edgesInset)
placeDistanceLabelView.autoPinEdge(.top, to: .bottom, of: placeTitleLabelView, withOffset: edgesInset / 2)
我在上面使用的所有其他元素都显示得很好,但我不明白为什么这些不是,它们只是标签时,但我无法获得使用它们的约束。