gpt4 book ai didi

iphone - 带背景图像的按钮 - iPhone 5 调整大小问题

转载 作者:行者123 更新时间:2023-12-03 20:51:47 26 4
gpt4 key购买 nike

我一直在到处寻找这里和谷歌,但我仍然有这个奇怪的问题,我无法弄清楚。我有一个应用程序图片如下,其中有 4 个应用了背景图像的 UIButton: enter image description here

当我在 iPhone 5 上调整大小/运行时,顶部按钮以一种非常奇怪的方式调整大小:

enter image description here

如何让所有 UIButtons 以与 iPhone 5 相同的方式调整大小?是否可以?我需要使用不同的方法吗?

我真的希望这不是重复的,但我完全被难住了。如果我更改 UIView 上其他位置的 UIButtons,则会调整不同的大小,或者会出现奇怪的间隙间距......我不明白。感谢您的帮助!

编辑:我在 Xcode 4.5 上使用 iOS 6。我正在 iPhone 4S 和 iPhone 5 上进行测试。我检查了 AutoLayout。如果我使用 Pin(刚刚找到它),我可以让 UIButton 保持其高度。

澄清我的问题。我希望 UIButton 调整大小,以便它们占据屏幕的相同百分比......我希望比例相同,而不是简单地添加一堆空白空间。我希望能说得更清楚

最佳答案

您可以使用的功能之一称为自动布局。它随 Xcode 提供,可以更轻松地针对 4 英寸屏幕进行调整。您可以在这里找到一个很好的例子:http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2

但据我所知,AutoLayout 仅适用于 iOS 6,这使得它“还不太有用”。我一直在使用一个名为 UIDevice 的类,其源代码可以在这里找到:https://github.com/erica/uidevice-extension并检查平台类型是否为 iPhone 5。我将其设置为在 View 加载时设置 GUI 的方法。我的实现示例:

UIImage *backgroundImage;

if ([[UIDevice currentDevice] platformType] == UIDevice5iPhone)
{
//I have a 4 inch screen present
myButton.frame = CGRectMake(x, y, w, h); //Set the frame as you would like it to look on the iPhone 5

backgroundImage = [[UIImage alloc] initWithCGImage:[UIImage imageNamed:@"main_background-568h@2x"].CGImage scale:2.0 orientation:UIImageOrientationUp];
}
else
{
//I have a 3.5 inch screen present
myButton.frame = CGRectMake(x, y, w, h); //Set the frame as you would like it to look on the iPhone 3, 3gs, 4, 4s...

backgroundImage = [[UIImage imageNamed:@"main_background"] retain];
}
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
[backgroundImage release];

希望事情能澄清一点。

关于iphone - 带背景图像的按钮 - iPhone 5 调整大小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13409178/

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