突出显示按钮按下它

突出显示按钮按下它

问题描述:

如何突出显示一个按钮,使用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

我插入代码 –

您可以更改按钮UIControlState

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

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

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