如何在Xcode中左对齐导航栏的标题?

如何在Xcode中左对齐导航栏的标题?,第1张

如何在Xcode中左对齐导航栏的标题?

您可以使用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))


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5126611.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存