Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将标签与PureLayout垂直对齐_Ios_Uiview_Alignment_Uilabel_Pure Layout - Fatal编程技术网

Ios 将标签与PureLayout垂直对齐

Ios 将标签与PureLayout垂直对齐,ios,uiview,alignment,uilabel,pure-layout,Ios,Uiview,Alignment,Uilabel,Pure Layout,我有一个简单的UIView子类,它包含一个标签。此子类具有以下init方法: override init(frame: CGRect) { super.init(frame: frame) self.autoSetDimension(.Height, toSize: 44) titleLabel.backgroundColor = UIColor.clearColor() titleLabel.translatesAutoresizingMaskIntoCons

我有一个简单的UIView子类,它包含一个标签。此子类具有以下init方法:

override init(frame: CGRect) {
    super.init(frame: frame)

    self.autoSetDimension(.Height, toSize: 44)
    titleLabel.backgroundColor = UIColor.clearColor()
    titleLabel.translatesAutoresizingMaskIntoConstraints = false
    titleLabel.numberOfLines = 0
    self.addSubview(titleLabel)

    titleLabel.text = "Some text"
    titleLabel.sizeToFit()

    titleLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: 20)
    titleLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: 20)
    titleLabel.autoAlignAxisToSuperviewAxis(.Horizontal)
}
实际上,标签的文本在运行时可能会更改,但无论如何,当我运行应用程序时,我看不到标签在其父视图中垂直居中。。。有人能帮我吗


提前谢谢

看看这个,如果它能帮到你

let label = UILabel()
    label.translatesAutoresizingMaskIntoConstraints = false

label.text = "Some dummy text"
self.view.addSubview(label)

let centreH = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 1)

let centreV = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 1)

self.view.addConstraint(centreH)
self.view.addConstraint(centreV)

什么是PureLayout?有自动布局库吗?@BharatModi