设置UIImageView的contentMode [英] Set contentMode of UIImageView
本文介绍了设置UIImageView的contentMode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Obj-C中
imageView.contentMode = UIViewContentModeScaleAspectFill;
会设置contentMode。
would set the contentMode.
为什么
imageView .contentMode = UIViewContentModeScaleAspectFill
在Swift中不起作用?
not work in Swift?
推荐答案
有些令人困惑的是,Swift删除了ObjC枚举值的前缀:
Somewhat confusingly, Swift drops the prefix for ObjC enum values:
imageView.contentMode = .scaleAspectFill
这是因为Swift已经知道正在使用什么枚举类型。或者,您也可以指定枚举:
This is because Swift already knows what enum type is being used. Alternatively, you can specify the enum too:
imageView.contentMode = UIViewContentMode.scaleAspectFill
注意:在版本3之前的Swift版本中,scaleAspectFill需要大写。
Note: In versions of Swift before version 3, "scaleAspectFill" will need to be capitalized.
这篇关于设置UIImageView的contentMode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文