Ríomhaire Ríomhaire - 1 year ago 159
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?

Answer Source

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