简体   繁体   中英

Xcode 5: How to align 2 object horizontally using Autolayout in IB?

I've got a UIImageView and a UILabel , one sit next to another with a fixed spacing (let say 10pt). The UILabel's width may change dynamically. Is it possible to align them centre horizontally like below ?

|    @ Abc    |
|             |
|             |

|   @ Abcde   |
|             |
|             |

Put both of them in a view like this:

|<-- center view  -->|
|  ________________  |
| |       View     | |
| |_______   ______| |
| | Image | | Label| |
| |_______| |______| |
| |________________| |
|                    |

Then center the view horizontal. Within the view you need to define constraints for the imageview and the label so that these define the height and width of the view.

EDIT Here are two images that show it works:

短文字 较长的文字

set UILabel's text alignment to center. then move it to the center of the view so that there's a guid line appear in the center of the UILabel. sorry, miss understood your mean, updating... select both label and image by holding command key then move them to align to the center guid line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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