【问题标题】:Weird NavBar stretching in ios 11 Xcode 9ios 11 Xcode 9中奇怪的导航栏拉伸
【发布时间】:2017-09-21 18:14:32
【问题描述】:

我的 NavBar 按钮 atm 有点问题。我升级到 Xcode 9 / ios 11,突然间 UIBarButtonItems 曾经是导航栏侧面的小按钮(如标准 ios 应用程序中的后退或编辑按钮)已经开始大量拉伸。这是一张照片:

我的代码很简单:

self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: image2, style: .plain, target: self, action: #selector(messageScreen))

有谁知道如何解决这个问题?谢谢。

【问题讨论】:

    标签: ios swift xcode ios11 xcode9


    【解决方案1】:

    斯威夫特:

    let widthConstraint = button.widthAnchor.constraint(equalToConstant: 30)
    let heightConstraint = button.heightAnchor.constraint(equalToConstant: 30)
    heightConstraint.isActive = true
    widthConstraint.isActive = true
    

    目标 C:

    [button.widthAnchor constraintEqualToConstant:30].active = YES;
    [button.heightAnchor constraintEqualToConstant:30].active = YES;
    

    //在设置导航按钮之前添加这些行

    【讨论】:

    • 你能给我这段代码的objective-c版本吗?
    • 对不起,我不知道objective-c。
    • @priyadharshini 嘿,一年后我添加了客观 c 版本:D
    • 哈哈哈@Okan 你两年后学会了Objective-C :D
    【解决方案2】:

    尝试为您的图标使用适当的大小。 Human Interface Guidelines iOS

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-10
      • 1970-01-01
      • 2023-04-09
      • 2020-01-25
      • 2018-02-12
      • 2018-03-12
      • 2018-01-03
      相关资源
      最近更新 更多