gpt4 book ai didi

iOS 确保栏按钮项目在 iPhone SE 的 UINavigationBar 中显示为全尺寸

转载 作者:行者123 更新时间:2023-11-28 14:48:37 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个导航栏,我在其中使用右侧的三个按钮。我这样创建它:

let button1 = UIBarButtonItem(image: UIImage(named: "button1"),
style: .plain,
target: self,
action: #selector(self.button1Tapped))

// Repeat for button2 and button3

navigationItem.rightBarButtonItems = [button1, button2, button3]

除 iPhone SE 外,这按预期工作。右栏按钮可以占据导航栏宽度的百分比似乎有某种固定限制,而在 iPhone SE 的小屏幕上超过了这个限制。因此,最右边的按钮缩小到其他按钮大小的一半左右。

我没有设置标题,所以有足够的空间让所有 3 个按钮都显示为全尺寸 - 即使在 iPhone SE 上也是如此。但是,我不确定如何在代码中指定它;有什么方法可以增加此限制(或导致按钮缩小的任何功能)以确保所有 BarButtonItems 在 iPhone SE 上显示全尺寸?

最佳答案

这不是最 Eloquent 做事方式,但它应该有效。

iPhone SE 屏幕尺寸为 w:320 x h:568 Apple Screen Display Sizes

您可以为 iPhone SE 调整图像大小并执行如下操作:

var button1: UIBarButtonItem!
var button2: UIBarButtonItem!
var button2: UIBarButtonItem!

// check the screen's dimensions
if UIScreen.main.bounds.width == 320 && UIScreen.main.bounds.height == 568{

// you may have to play around with it but resize the UIImage(named: "button1") to fit the iPhone SE
button1 = UIBarButtonItem(image: UIImage(named: "button1_Resized"),
style: .plain,
target: self,
action: #selector(self.button1Tapped))

// Repeat for button2 and button3
// resize the UIImage(named: "button2_Resized") and UIImage(named: "button3_Resized") to fit the iPhone SE

} else{

// anything other then the iPhone SE will get the regular sized images
button1 = UIBarButtonItem(image: UIImage(named: "button1"),
style: .plain,
target: self,
action: #selector(self.button1Tapped))

// Repeat for button2 and button3
}

navigationItem.rightBarButtonItems = [button1, button2, button3]

关于iOS 确保栏按钮项目在 iPhone SE 的 UINavigationBar 中显示为全尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50034768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com