Ríomhaire Ríomhaire - 5 months ago 12x
iOS Question

Set contentMode of UIImageView

In Obj-C

imageView.contentMode = UIViewContentModeScaleAspectFill;

would set the contentMode.

Why does

imageView.contentMode = UIViewContentModeScaleAspectFill

not work in Swift?


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