4
A
回答
9
要做到這一點,首先要確保你在視圖控制器提供的圖像(在您的故事板創建圖像之間的關聯,並在您的視圖 - 控制)。
讓我們假設它名爲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)
ŧ他會實際將圖像動態分配給圖像。你可能只是這樣做,或者如果你從字面上做的把它變成一個按鈕,點擊就可以只取我上面指定的更簡單的方法簡單的東西。
謝謝你讓我知道如果有任何問題!
相關問題
- 1. 斯威夫特 - 圖像不顯示
- 2. 斯威夫特:刷新UIImageView圖片
- 3. 截圖顯示空白 - 斯威夫特
- 4. 斯威夫特轉換斯威夫特
- 5. 斯威夫特2斯威夫特3
- 6. 斯威夫特 - JSQMessagesViewController與斯威夫特
- 7. 斯威夫特MapKit不顯示指示
- 8. 斯威夫特3 - UIImageView圖像得到收縮
- 9. 斯威夫特 - 圖像色彩復位時顯示警告
- 10. 如何顯示SVG圖像與斯威夫特
- 11. 訪問字符串鍵顯示獲取圖像(斯威夫特)
- 12. 斯威夫特。從網站顯示圖像(xxx.?action=stream)
- 13. 斯威夫特遊樂場圖像不顯示它應該
- 14. 斯威夫特 - 顯示與按鍵
- 15. PFLoginViewController並沒有顯示斯威夫特
- 16. 顯示只有斯威夫特
- 17. 斯威夫特collectionViewCells沒有顯示
- 18. 斯威夫特
- 19. 斯威夫特
- 20. 斯威夫特
- 21. 斯威夫特
- 22. 斯威夫特
- 23. 斯威夫特
- 24. 斯威夫特
- 25. 斯威夫特
- 26. 斯威夫特
- 27. 斯威夫特
- 28. 斯威夫特
- 29. 斯威夫特
- 30. 斯威夫特