ios - 向导航栏添加约束

标签 ios swift

我需要在我的应用中实现这个设计,但我想不出一种方法来将这个约束添加到导航栏。

我尝试将约束添加到具有负偏移量的顶部布局指南,但导航栏始终在顶部

enter image description here

有没有办法使用 NSLayoutconstraints 来创建带有导航栏的特定布局?

最佳答案

要实现此设计,您可以通过以下代码将按钮放在窗口 View 上。

UIWindow *appWindow = [[[UIApplication sharedApplication] delegate] window];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeSystem];
[aButton setFrame:CGRectMake((appWindow.frame.size.width/2)-35, 20, 70, 100)];
[appWindow addSubview:aButton];

此外,您还可以使用

[[UIApplication sharedApplication] keyWindow]

获取窗口

关于ios - 向导航栏添加约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43058632/

相关文章:

swift - 如何在 swift 中为 detailTextLabel 加粗文本

ios - 在 Swift 中通过 Promise 传递值

ios - 有没有办法只旋转ios中按钮的文本

ios - 如果登录成功,如何关闭登录 View ? swift

java - 如何在 Wi-Fi 中的设备之间同步数据

php - 如何在 iOS 中将 base64_encode 从 PHP 重写为 Swift 3?

Swift 在构建子节点时给出 "self used before all stored procedures are initialized"错误

swift - 为什么这会造成这么多麻烦? (相关类型的协议(protocol)和类型别名)

swift - 如何在 Xcode 9.3 中切换到 Swift 4.0?

ios - 球体上的快速视频,黑屏但可以听到音频