Ríomhaire Ríomhaire - 2 years ago 211
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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download