您可以使用navigationItems titleView添加具有左对齐的UILabel,然后使用自动布局设置其框架,如下所示:
let label = UILabel()label.text = "Title Label"label.textAlignment = .leftself.navigationItem.titleView = labellabel.translatesAutoresizingMaskIntoConstraints = falselabel.superview?.addConstraint(NSLayoutConstraint(item: label, attribute: .centerX, relatedBy: .equal, toItem: label.superview, attribute: .centerX, multiplier: 1, constant: 0))label.superview?.addConstraint(NSLayoutConstraint(item: label, attribute: .width, relatedBy: .equal, toItem: label.superview, attribute: .width, multiplier: 1, constant: 0))label.superview?.addConstraint(NSLayoutConstraint(item: label, attribute: .centerY, relatedBy: .equal, toItem: label.superview, attribute: .centerY, multiplier: 1, constant: 0))label.superview?.addConstraint(NSLayoutConstraint(item: label, attribute: .height, relatedBy: .equal, toItem: label.superview, attribute: .height, multiplier: 1, constant: 0))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)