解决方法
要做到这一点,首先要确保在viewcontroller中有可用的图像(通过在storyboard上和viewcontroller中创建图像之间的关联).
让我们假装它叫做imageView.
以编程方式,您可以说:
imageView.image = UIImage(named: ("nameofasset"))
class func Getimage(someValueWhichDrivesLogic: Int)->UIImage { if (someValueWhichDrivesLogic == 1) { assetName = "imageone" //note you don't add .png,you just give it the same name you have in your standard images folder in XCode6 } else if (someValueWhichDrivesLogic == 2) { assetName = "imagetwo" //again,this is the actual name of my image } //Return an image constructed from what existed in my images folder based on logic above return UIImage(named: (assetName)) }
所以现在已经创建了上面的函数,你可以这样做:
imageView.image = Getimage(1) imageView.image = Getimage(2)
这实际上会将图像动态分配给图像.你可以这样做,或者如果你真的做了一些简单的事情,就像点击按钮一样,你可以采取我上面指定的更简单的方法.
如果有任何问题,请告诉我!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。