gpt4 book ai didi

ios - UIButton 图像未调整大小 - Swift

转载 作者:行者123 更新时间:2023-11-29 01:01:35 24 4
gpt4 key购买 nike

我正在创建一个带有 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)

关于ios - UIButton 图像未调整大小 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36930133/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com