Ríomhaire Ríomhaire - 6 months ago 31
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

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
Comments