作者:手机用户2502853457 | 来源:互联网 | 2023-01-11 18:14
是否可以更改大导航栏标题的x偏移?我想将x偏移更改为36pt。
1> TiM..:
I just discovered in the latest version of iOS 12, if you simply modify the layoutMargins
property of the UINavigationBar
, this will affect the large title.
let navigatiOnBar= navigationController.navigationBar
navigationBar.layoutMargins.left = 36
navigationBar.layoutMargins.right = 36
I tried the solution mentioned here about using a custom NSMutableParagraphStyle
. That does indeed work, but because it stretches the UILabel
view that the large title is made of, when you swipe downwards, the subtle animation it plays where the text grows slightly becomes quite distorted.
大提示。如果您使用的是搜索栏,这也可以使用:“ searchController.searchBar.layoutMargins.left = X”。
2> 小智..:
您可以通过以下方式添加其他偏移量:
if #available(iOS 11.0, *) {
let navigatiOnBarAppearance= UINavigationBar.appearance()
let style = NSMutableParagraphStyle()
style.alignment = .justified
style.firstLineHeadIndent = 18
navigationBarAppearance.largeTitleTextAttributes = [NSAttributedStringKey.paragraphStyle: style]
}