我在我的應用程序中設置了圖像的自定義按鈕。我想從按鈕獲取圖像並存儲在UIImage變量中。請引導我。如何從UIButton獲取圖像?
15
A
回答
56
這個怎麼樣?
UIImage *img = [button imageForState:UIControlStateNormal];
0
UIImage *myNewImage = [UIButton imageForState:UIControlStateNormal];
雖然這不是很好的設計實踐。我這樣做:
UIImage *myNewImage = [UIImage imageNamed:@"name of image that is in your bundle"];
1
雨燕3.0語法
let image: UIImage = yourButton.image(for: .normal)!
相關問題
- 1. 從[self.view viewWithTag:n]獲取UIButton時無法獲取UIButton圖像;
- 2. 如何從iPhone SDK上的UIButton獲取圖像名稱?
- 3. 獲取UIButton的背景圖像
- 4. 從UIButton獲取UILabel
- 5. 如何從gridView獲取圖像(位圖)
- 6. 如何從PNG圖像獲取圖標?
- 7. 如何從UIButton獲取對象ID?
- 8. 如何設置UIButton圖像?
- 9. 如何獲取UIButton ID?
- 10. 如何正確地將圖像從UIButton放入圖像?
- 11. 如何從圖像獲取SRC jQuery中
- 12. 如何從ImageIcon中獲取圖像(obj)
- 13. Sharepoint - 如何從RichTextField獲取圖像?
- 14. 如何從圖像中獲取信息?
- 15. 如何從圖像中獲取src
- 16. 如何從Amazon S3 Bucket獲取圖像?
- 17. 如何從ApiControler獲取圖像
- 18. 如何從掃描儀獲取圖像?
- 19. 如何從轉推中獲取圖像?
- 20. 如何從圖像中獲取文本?
- 21. 如何從Rss中獲取圖像?
- 22. 如何從AjaxFileUpload獲取base64圖像?
- 23. 如何從圖像獲取座標CGRectMake
- 24. 如何從RichEditBox中獲取圖像
- 25. 如何從HBase獲取圖像
- 26. 如何從uri獲取圖像ID?
- 27. 如何從ACF圖庫圖像獲取圖像元數據?
- 28. 如何從使用jquery的點擊圖像獲取圖像ID?
- 29. 如何從java中的圖像網格獲取一個圖像?
- 30. 如何從圖像url中獲取圖像數據
感謝Zoul。它的工作。 – Siddiqui 2011-01-28 10:41:34
請問我該如何獲取圖片名稱? – 2017-06-22 11:00:17