首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIButton UIEdgeInsets不工作

UIButton UIEdgeInsets不工作
EN

Stack Overflow用户
提问于 2017-04-16 12:17:38
回答 2查看 1.5K关注 0票数 2

因此,我查看了堆栈溢出上的所有项目,以便在UIImages中为UIButton添加边缘嵌入,但它们都没有工作。当我构建项目时,图像是通过按钮的边界设置的--它没有设置到嵌入式,我也不知道为什么。以下是代码:

代码语言:javascript
复制
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{

    }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-16 14:43:18

imageEdgeInsets是用来定位图像的,而不是背景图像!

使用setImage而不是setBackgroundImage

票数 3
EN

Stack Overflow用户

发布于 2017-04-16 13:53:56

如果AnimatableButton是UIButton,为什么要在按钮中添加按钮?我不知道你真正的目的是什么,但你可以试试Settingsbutton.contentEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43437141

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档