问题
I have to show the Name and EmailID aligned horizontally properly with the Profile Image . So that the Name and email ID appears exactlybat the center of the UIImageView.
But you can see the name and email id are not in centre with the profile image. Why is this happening? I have given the following constraints:
回答1:
Remove leading and trailing Constrain and set align center x to imageView.
You can also set leading and trailing Constrain. but both are equal as follow.
回答2:
Just control+drag
from label to imageview and select Center Horizontally.
回答3:
Ctrl drag from the labels to the imageview and choose Center horizontally
.
回答4:
I know the question has been answered but this is best solution horizontal stack view
回答5:
Ctrl+drag from image and labels to their superview and select Center Horizontally in Container
.
回答6:
Using AutoResizing Tool:
Step1: Place your image view and labels exactly how do you needed.
Step2: Select Image view and click on Size Inspector.
Step3: Simply click on red bars of autoresizing subview to de-select it which is shown in below image.
Step4: Repeat same steps for labels. I made labels text alignment as centre.
来源:https://stackoverflow.com/questions/45768584/how-to-align-uilabel-horizontally-with-the-profile-photo-image