我在我的應用程序中設置了圖像的自定義按鈕。我想從按鈕獲取圖像並存儲在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. 從UIButton獲取圖像
- 2. 從[self.view viewWithTag:n]獲取UIButton時無法獲取UIButton圖像;
- 3. 如何從iPhone SDK上的UIButton獲取圖像名稱?
- 4. 獲取UIButton的背景圖像
- 5. 從UIButton獲取UILabel
- 6. 如何從圖庫中獲取圖像
- 7. 如何從gridView獲取圖像(位圖)
- 8. 如何從PNG圖像獲取圖標?
- 9. 如何從UIButton獲取對象ID?
- 10. 如何設置UIButton圖像?
- 11. 如何獲取UIButton ID?
- 12. 如何正確地將圖像從UIButton放入圖像?
- 13. 如何從圖像獲取SRC jQuery中
- 14. 如何從轉推中獲取圖像?
- 15. 如何從webForm中獲取圖像?
- 16. 如何從MySQL獲取圖像爲Android
- 17. 如何從php中獲取圖像?
- 18. 如何從Rss中獲取圖像?
- 19. 如何從UIImageView獲取圖像?
- 20. 如何從圖像獲取src標籤?
- 21. 如何從uri獲取圖像ID?
- 22. 如何從捲曲中獲取圖像
- 23. 如何從order_id獲取選項圖像
- 24. 如何從AjaxFileUpload獲取base64圖像?
- 25. 如何從ApiControler獲取圖像
- 26. 如何從圖像中獲取區域?
- 27. 如何從ImageButton獲取圖像?
- 28. 如何從AGImagePickerController獲取圖像
- 29. 如何從HBase獲取圖像
- 30. 如何從Amazon S3 Bucket獲取圖像?
感謝Zoul。它的工作。 – Siddiqui 2011-01-28 10:41:34
請問我該如何獲取圖片名稱? – 2017-06-22 11:00:17