Set contentMode of UIImageView

后端 未结 5 1146
清歌不尽
清歌不尽 2020-12-15 16:36

In Obj-C

imageView.contentMode = UIViewContentModeScaleAspectFill;

would set the contentMode.

Why does

imageView.contentM

5条回答
  •  轮回少年
    2020-12-15 17:19

    Somewhat confusingly, Swift drops the prefix for ObjC enum values:

    imageView.contentMode = .scaleAspectFill
    

    This is because Swift already knows what enum type is being used. Alternatively, you can specify the enum too:

    imageView.contentMode = UIViewContentMode.scaleAspectFill
    

    Note: In versions of Swift before version 3, "scaleAspectFill" will need to be capitalized.

提交回复
热议问题