( Autoresizing mask ) flexible width of an image with fixed height

前端 未结 2 713
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 03:18

I have been playing around with iPhone interface building using only code and not using IB.

Now I\'m facing the following problem:

How can I set an image to

2条回答
  •  自闭症患者
    2020-12-08 03:51

    Horizontally:

    • Resize keeping fixed left/right margins: UIViewAutoresizingFlexibleWidth
    • Keep size and same distance from the left: UIViewAutoresizingFlexibleRightMargin
    • Keep size, stay centered: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
    • Keep size and same distance from the right: UIViewAutoresizingFlexibleLeftMargin

    Vertically:

    • Resize keeping fixed top/bottom margins: UIViewAutoresizingFlexibleHeight
    • Keep size and same distance from the top: UIViewAutoresizingFlexibleBottomMargin
    • Keep size, stay centered: UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin
    • Keep size and same distance from the bottom: UIViewAutoresizingFlexibleTopMargin

    Combine one from the first section with one from the second with a |. For example, to have it resize horizontally and keep the same size and distance from the top vertically, you'd use UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin.

    You can use other combinations to do some more tricky things, but those are the basics.

提交回复
热议问题