Objective C: Adaptive Toolbar

主宰稳场 提交于 2020-01-16 10:00:08

问题


I want to create a toolbar without using the UIToolbar, instead I used image views and UIButtons but when I change the orientation of my iPad they remain where they are positioned.

Why didn't I use UIToolbar? Because I am having problems with the spacing of my buttons, because I want them closer to each other but on UIToolbar the space are wide.

If there is a way to change the spacing maybe I'll go back to UIToolbar.

Now, my question is how can I make the image views and UIButtons adaptive to the orientation?


回答1:


In interface builder, in your xib file, open size inpector. There, use autosizing feature. arrows inside square are about resizing selected view. Liness outside of square are about getting origing point. You may allso change origin point's position there. just make all ypur objects to move/resize as you what there.




回答2:


Use UIToolbar and in between the buttons put a UIBarButtonSystemItemFixedSpace and set its width using the width property.

From the docs:

UIBarButtonSystemItemFixedSpace Blank space to add between other items. Only the width property is used when this value is set.

You can keep going with your own implementation of course, but users are expecting a toolbar to look and feel like a UIToolbar. Not only that, but it does everything you need it to do.

The general rule with apple provided UI elements is that they provide what you need, and if they don't, it is not hard to add what you need with a subclass. Starting from scratch is rarely needed.



来源:https://stackoverflow.com/questions/8147355/objective-c-adaptive-toolbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!