Storyboard and autolayout: how make a circular image

前端 未结 7 600
逝去的感伤
逝去的感伤 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:32

    In storyboard i have set the image to "Scale to fit" mode

    But that's a problem, isn't it? It means: "Stretch the image so that it matches the way the image view is stretched." If that isn't what you want, don't say that! Use Centered, or at least use one of the content modes with "Aspect" in its name so that your image is not stretched.

    As for the circle itself, setting the cornerRadius is no way to make a circle. The way to create a circular boundary around an image is to mask the image. You can redraw the image with the circular mask as a clipping boundary, or you can apply the circular mask to the image view. (See, for example, my answer here: https://stackoverflow.com/a/16475824/341994.)

    It is true that your image view is also being stretched, because you gave it constraints to both sides of the superview. You can prevent that by giving it a width constraint instead; now its width will be absolute. But you should still do the right thing on the other two issues.

提交回复
热议问题