2016-09-14 191 views
1

如何突出顯示一個按鈕,使用textLabel按下圖像替換爲正常按鈕?當我按下這個按鈕Picture時,動作將被激活,但沒有按鈕本身的反饋。突出顯示按鈕按下它

import UIKit 
import AVFoundation 

class PlayMusicViewController: UIViewController { 

    var audioPlayer: AVAudioPlayer! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     var daten = NSBundle.mainBundle().pathForResource("Kool_Savas_Auge", ofType: "mp3") 

     var filePathUrl = NSURL.fileURLWithPath(daten!) 

     do{ 
      audioPlayer = try AVAudioPlayer(contentsOfURL: filePathUrl, fileTypeHint: nil) 

       } 
     catch let err as NSError{ 
      print(err.debugDescription); 
     } 

    } 

    @IBAction func PlayMusic(sender: UIButton) { 

     audioPlayer.play() 

    } 
    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 


    /* 
    // MARK: - Navigation 

    // In a storyboard-based application, you will often want to do a little preparation before navigation 
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
     // Get the new view controller using segue.destinationViewController. 
     // Pass the selected object to the new view controller. 
    } 
    */ 

} 
+0

嗨 - 你問如何的目標,你會添加一個UIImageView到一個UIButton?除了你不希望圖像像UIButton那樣「點擊」?另外,你是在談論iOS還是OSX? – Sparky

+1

使用相關代碼更新您的問題,以獲得目前爲止所做的一切。 – rmaddy

+0

我插入代碼 –

回答

0

您可以更改按鈕UIControlState

// Text 
button.setTitleColor(UIColor.greenColor(), forState: .Highlighted) 

// Image 
button.setImage(UIImage(), forState: .Highlighted)) 

// Background image 
button.setBackgroundImage(UIImage(), forState: .Highlighted)