热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

iOS11-导航栏大标题自定义偏移

如何解决《iOS11-导航栏大标题自定义偏移》经验,为你挑选了2个好方法。

是否可以更改大导航栏标题的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]
}


推荐阅读
author-avatar
手机用户2502853457
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有