简体   繁体   English

迅速4和Xcode autoLayout和UIImageview作为按钮

[英]swift 4 and Xcode autoLayout and UIImageview as Button

I am working on auto layout and making those UIIMages as Button. 我正在进行自动布局并将这些UIIMages设置为Button。 I would like to make those button to be clicked and switch the images as well as showing some words in the label. 我想单击这些按钮并切换图像,以及在标签中显示一些单词。

In this case what should I do? 在这种情况下,我该怎么办?

In addition, as it is shown, the auto layout ratio is different only from the iPhone SE. 此外,如图所示,自动布局比例仅与iPhone SE不同。 In. 在。 this case What should I consider? 这种情况下我应该考虑什么?

Many thanks, 非常感谢, 故事板截图

The first thing you need to learn is auto layout . 您需要学习的第一件事是自动布局 Start with basic Always go with Apple's doc first 从基本开始始终先阅读Apple的文档

This one I likes he is good and you will also find how to use buttons as image view, using card game example, check other tutorials also very helpfull. 我喜欢这个人,他很好,您也会发现如何将按钮用作图像视图,使用纸牌游戏示例,查看其他教程也非常有帮助。 Stanford university autolayout by Michel Deiman 斯坦福大学自动布局,作者:Michel Deiman

As far, your question just gives your label Horizontal in the container constraints(open storyboard in the right bottom third from last (allin) click on it popUp will open), and 20 bottom to the buttons and it will be in the centre. 到目前为止,您的问题只是在容器约束中给标签设置了“水平”(在最后一个(allin)的右下三分之一处打开情节提要,然后单击它,弹出窗口将打开),按钮的底部20处在中间。 Every elements need x,y height and width so it knows exactly where to place, so you also need to give constraints to the buttons, Learn stackView to understand how to place your button without giving many constraints to each button and stack view will handle it for you, try hide and show to one of the button and magically stack view will adjust all adjustment. 每个元素都需要x,y的高度和宽度,因此它确切知道放置的位置,因此您还需要对按钮进行约束,了解stackView以了解如何在不对每个按钮施加很多约束的情况下放置按钮,并且堆栈视图将对其进行处理对于您来说,请尝试隐藏并显示到按钮之一,然后神奇的堆栈视图将调整所有调整。 I suggest before staring Do read apple's doc first. 我建议在凝视之前,先阅读苹果的文档。

And Your question is too broad to answer, so read and try adding different constraints based on your need and ask a specific question(after trying by yourself) like why this label getting cut what constraints should i add so people know exactly what you want to achieve, people are always ready to help, just ask the right question. 而且您的问题过于广泛而无法回答,因此请阅读并尝试根据您的需要添加不同的约束条件,并提出一个具体的问题(在您自己尝试之后),例如为什么这个标签会减少我应添加的约束条件,以便人们确切地知道您想要什么实现目标时,人们总是愿意提供帮助,只是提出正确的问题。

happyCoding happyCoding

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM