gpt4 book ai didi

iOS 以编程方式居中对象

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:16:30 26 4
gpt4 key购买 nike

我正在更新一个应用程序以支持 iPhone 6 Plus。在以编程方式设置的其中一个 View 上,在 5S 或更低版本上运行时,所有 View 都以它们应有的方式居中。然而,在 6 Plus 上,它略微向左移动。我如何调整此代码以使其在所有版本中都水平居中?

[self.logInView.usernameField setFrame:CGRectMake(35.0f, 125.0f, 250.0f, 50.0f)];
[self.logInView.passwordField setFrame:CGRectMake(35.0f, 175.0f, 250.0f, 50.0f)];
[self.fieldsBackground setFrame:CGRectMake(35.0f, 125.0f, 250.0f, 100.0f)];
[self.logInView.logInButton setFrame:CGRectMake(35.0f, 235.0f, 250.0f, 40.0f)];

最佳答案

[self.logInView.usernameField setFrame:CGRectMake(self.view.center.x - 125, 0, 250.0f, 50.0f);];
[self.logInView.passwordField setFrame:CGRectMake(self.view.center.x - 125, 175.0f, 250.0f, 50.0f)];
[self.fieldsBackground setFrame:CGRectMake(self.view.center.x - 125, 125.0f, 250.0f, 100.0f)];
[self.logInView.logInButton setFrame:CGRectMake(self.view.center.x - 125, 235.0f, 250.0f, 40.0f)];

您可以使用此代码在所有 iOS 设备上很好地水平放置 UI。

关于iOS 以编程方式居中对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27883919/

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