Storyboard and autolayout: how make a circular image

前端 未结 7 695
逝去的感伤
逝去的感伤 2021-01-01 02:27

in storyboard (xcode 6) i want a circular user image profile take from Facebook.

So i have make this interface in storyboard, using auto layout:

7条回答
  •  灰色年华
    2021-01-01 02:35

    Two steps:

    1. Center the UIImageView by adding a "Horizontal Center In Container" constraint (Editor > Align > Horizontal Center in Container) to the UIImageView.
    2. Remove the leading and trailing constraints you currently have set on the UIImageView.

    Why? The UIImageView is getting stretched because Auto Layout needs to account for the leading and trailing constraints you set on the UIImageView. To prove my point, set the priority of the leading and trailing constraints to something less than the priority of the height and width constraints. You should see a rounded image like you expect, but it may not be centered.

提交回复
热议问题