gpt4 book ai didi

ios - UIButton UIEdgeInsets 不起作用

转载 作者:搜寻专家 更新时间:2023-11-01 07:13:47 25 4
gpt4 key购买 nike

因此,我查看了 Stack Overflow 上所有为 UIButton 中的 UIImages 添加边缘插图的项目,但没有一个起作用。当我构建项目时,图像只是通过按钮的边界设置 - 它没有设置为插图,我不知道为什么。这是代码:

let Settingsbutton = AnimatableButton(frame: CGRect(x: 23, y: 30, width: 40, height: 40))
Settingsbutton.layer.cornerRadius = Settingsbutton.frame.size.height / 2
Settingsbutton.layer.backgroundColor = UIColor.white
let roundedButton3 = UIButton(type: .custom)
roundedButton3.frame = Settingsbutton.frame
let _border3 = CAShapeLayer()
_border3.path = UIBezierPath(roundedRect: roundedButton3.bounds, cornerRadius:roundedButton3.frame.size.width/2).cgPath
_border3.frame = roundedButton3.bounds
_border3.strokeColor = UIColor.white.cgColor
_border3.fillColor = UIColor.clear.cgColor
_border3.lineWidth = 3.0

Settingsbutton.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10)
Settingsbutton.contentVerticalAlignment = .fill
Settingsbutton.contentHorizontalAlignment = .fill
Settingsbutton.layer.addSublayer(_border3)
self.view.addSubview(Settingsbutton)
self.view.bringSubview(toFront: Settingsbutton)

if PFUser.current() == nil{
Settingsbutton.setBackgroundImage(UIImage(named: "padlock"), for: .normal)

}else{

}

最佳答案

imageEdgeInsets 用于定位图像而不是背景图像!

使用setImage代替setBackgroundImage

关于ios - UIButton UIEdgeInsets 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43437141/

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