我正在创建一个带有png图像的自定义按钮,就像我以前做过数百次一样。
但由于某种原因,这一次图像没有随着按钮的大小而缩放。
func constructInfoViewBtns() {
let buttonsView = UIView.init(frame: CGRectMake(0, 90, self.infoView!.frame.width, 90))
let playPauseBtn = UIButton(type: UIButtonType.Custom) as UIButton
let playPauseBtnImg : UIImage = UIImage(named: "pauseBtn")!
playPauseBtn.setImage(playPauseBtnImg, forState: .Normal)
playPauseBtn.imageView?.contentMode = UIViewContentMode.ScaleAspectFill
playPauseBtn.frame = CGRectMake(0, 0, 55, 55)
playPauseBtn.backgroundColor = UIColor.blueColor()
playPauseBtn.center = CGPointMake(buttonsView.frame.width/2, buttonsView.frame.height/2)
playPauseBtn.addTarget(self, action: "playPauseTrack:", forControlEvents: .TouchDown)
self.playPauseBtn = playPauseBtn
buttonsView.addSubview(self.playPauseBtn!)
self.infoView!.addSubview(buttonsView)
}
我得到的是一个蓝色框,其中的按钮图像小于按钮的边框。就像是垫的什么的。。。
添加此项并尝试
playPauseBtn.imageEdgeInsets = UIEdgeInsetsMake(25,25,25,25)