![](/img/trans.png)
[英]How do I pass an image view and its properties from one view controller to another?
[英]how do I pass my button image to an Image view when its clicked?
我認為這是一個非常簡單的過程,但是我尚不清楚正確的語法,但這是我到目前為止所做的:
@IBOutlet weak var notesImage: UIImageView!
@IBAction func MusicNote(sender: AnyObject) {
self.sendButtonImage()
}
// This is where the button image is sent to the UIImageView once that specific button is pressed
func sendButtonImage() {
var note = MusicNote(sender: AnyObject)
這是一些粗略的代碼,您可能需要拆開一些可選選項,但是理論應該起作用。 我個人將圖像設置在viewDidAppear
方法的按鈕上,或者通過編程方式完成。 然后使用backgroundImageForState
方法再次檢索圖像。 在此處查看UIButton的文檔。
//Set this in view did appear, ect..
var firstImage = UIImage(named: "image1")
var secondImage = UIImage(named: "image2")
var thirdImage = UIImage(named: "image3")
button1.setBackgroundImage(firstImage!, forState state: UIControlState.SomeState)
button2.setBackgroundImage(secondImage!, forState state: UIControlState.SomeState)
button3.setBackgroundImage(thirdImage!, forState state: UIControlState.SomeState)
//End code that should be in viewDidAppear
func buttonTapped(button1: UIButton?){
imageView.image = button1.backgroundImageForState(UIControlState.SomeState)!
}
如果您需要更多幫助,請告訴我,如果您發現我的帖子有用,也不要忘了投票,並接受它是否可以幫助您解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.