gpt4 book ai didi

ios - 如何在Xcode中正确设置UIButton的约束(如图)?

转载 作者:行者123 更新时间:2023-11-29 05:50:03 25 4
gpt4 key购买 nike

背景:

我正在为要在Xcode中构建的游戏创建商店,使用的是SceneKit用于游戏,SpriteKit用于叠加层,UIKit用于商店以及我可能创建的任何其他非叠加视图。我有9个按钮,所有按钮的默认大小为700x700,在情节提要中缩小为90x90。我正在尝试让所有9个文件都以3x3格式显示,该格式根据用户的屏幕大小调整和间隔。

注意:contentView是一个UIView,背景为浅蓝色,包含我所有的按钮。

(图片1)我希望它在所有屏幕上都显示为(减去蓝色轮廓):
https://prnt.sc/ndzqbz

(图2)在我为其设计的设备(Iphone 7 Plus)上的外观:http://prntscr.com/ndzrkn

(图3)在另一台设备(I pad Pro 12.9inch 3rd gen)上的外观:
http://prntscr.com/ndzrrh

题:

我将如何使图像2和3更接近图像1?

我已经看过大量的自动布局约束视频,并且遍历整个网络,却一无所获。每当我尝试尝试某些操作时,Image 3都会更加混乱。
注意:图片3是我以前使用过的“清理过的”版本,它曾经在所有原本不应该使用的地方都具有各种形状和大小的按钮。

我也尝试过在Swift 5.0中解决此问题的程序设计方法:

码:

func setupButtons() {
player_button.frame = CGRect(x: contentView.self.frame.midX, y: contentView.self.frame.midY, width: 200, height: 200)
}


我认为应该做的是将我的按钮放在视图的中间,并增加按钮的大小。它确实增加了按钮的大小,但是在Ipad屏幕上将其放置在此处: http://prntscr.com/ndzxgo
不在我想要的contentView中间。
看来已完成的工作是采用contentViews的原始大小并使用了该大小。我似乎也无法获得应用了约束的contentView的大小(我碰巧使我的contentViews约束在大多数情况下都起作用)。

要考虑的其他事项:

•我尝试过调整图像大小并将其放入堆栈视图
  -我无法正常工作

感谢您的任何反馈!

最佳答案

As suggested in comment with the help of CollectionView also possible. But I have tried with UIButton with size 90x90 and placed in the center of the view.
below are the constraint added to the button
Align Center X to : Superview
Align Center Y to : Super view
width equals : 90
Height equals : 90

and add the remaining button.
Please find the below link for adding constraints to all button.

Below are the screen shots.

ipad https: https://prntscr.com/ne175m
iphone 5s . https://prntscr.com/ne174t
iphone 7 plus https://prntscr.com/ne175x
constraints https://prntscr.com/ne10vl



Please change UIButton background images as per your requirement

关于ios - 如何在Xcode中正确设置UIButton的约束(如图)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55757209/

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