iOS布局问题请教
大家讲道理
大家讲道理 2017-04-18 09:26:21
0
4
319

学习了几天iOS(依然小白)
之前是做Android的
我想问下 是否有像Android那样的可以在布局文件xml中设置高度呢

现在我只知道在xib中设置了 无效
是不是iOS要控制view的高度 必须要在代码中通过CGRectMake来设置吗

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(4)
刘奇

The respondent is also a technical scumbag who has been writing Android for several years before coming to iOS. I felt uncomfortable with iOS at first, but after a few months of writing and getting used to it, I discovered that I could no longer write Android well. Because iOS is actually much more convenient to write than I originally thought, and it is also much more convenient than Android.

As for the reason why I rejected iOS development when I first started learning, it is largely due to the somewhat bad experience of Xcode. Xcode has a big problem: Functions that are obviously very convenient and commonly used are placed in the corner as icons without even prompting.

The same is true for Interface Builder’s AutoLayout constraint function—the four inconspicuous small icons placed in the lower right corner of the visual editing area. Select a control and click the second button to set horizontal and vertical centering constraints; click the third button to set the distance, fixed width, fixed height, and fixed aspect ratio from the top, bottom, left, and right nearest controls; the last button is used to set Good constraints update the view. The functions of these four buttons are even more powerful: if you hold down the command to select multiple controls, you can set the alignment of multiple controls, etc.

Once a control has constraints set, it has an implicit tendency to adapt to its content unless some constraints are forced to change its size.

If multiple adaptive content controls such as UILabel are arranged together, also pay attention to the Content Hugging Priority and Content Compression Resistance Priority at the bottom of the "Size" label in the property bar on the right. The respondent's vocabulary is shallow and he cannot describe this function clearly at the moment. He can only say that it is a bit like layout_weight in Android.

The idea of ​​AutoLayout is also something that developers who switch from Android to iOS should pay special attention to. In particular, the number of constraints must be just right, neither too few to cause ambiguity nor too many to cause conflicts; the constraints of each control must be enough to determine its Horizontal position, vertical position, width and height (UILabel, etc. can adapt to the content, so there is no need to determine the width and height).

In the respondent’s own practice, AutoLayout can realize many needs that Android Layout cannot achieve (it may also be because the respondent does not know enough about Android). Therefore, although beginners may feel that AutoLayout is not as convenient as Android Layout, once developers master the various uses of AutoLayout, they will find it an equally convenient and more powerful tool.

伊谢尔伦

Can you post the xib screenshot and code? In some cases, autolayout is turned on by default

左手右手慢动作

You can set the height directly in xib, but it is not flexible enough. You can learn about AutoLayout

大家讲道理

ios now uses autolayout layout, of course you can turn off and use "absolute positioning". Autolayout is somewhat similar to the current constraintslayout of android. There are some similarities with relativelayout, but not that many. To use it, place the cursor on your view and then ctrl+drag. Then set specific parameters.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template