【问题标题】:Round Border With Background Image Button swift带背景图像按钮的圆形边框swift
【发布时间】:2018-06-22 11:40:25
【问题描述】:

我正在使用此代码创建带有背景图像的圆形边框按钮

{  
  Button.layer.cornerRadius = clear.frame.width/2 
  Button.clipsToBounds = true
  Button.layer.borderWidth = 5.0
  Button.layer.borderColor = UIColor(displayP3Red: 91/256, green: 87/256, blue: 115/256, alpha: 1.0).cgColor
}

结果如下:

我想在按钮和圆角边框之间创建一个边距来达到这个结果:

提前致谢

【问题讨论】:

  • 感谢大家编辑我的问题,我是初学者,所以非常抱歉出现错误

标签: ios swift uibutton


【解决方案1】:

您可以将其设置为 UIButton 的图像,而不是设置背景图像。

let image = UIImage(named: "imageName")
yourButton.setImage(image, for: .normal)

使用 Storyboard,来自属性检查器。

您还可以从尺寸检查器中设置内容、标题和图像插入(上、左、下和右)。

  • 设置 Content Insets 以同时设置图片和标题。
  • 设置 Title Insets 以一次设置标题。
  • 设置Image Insets一次设置图像。

【讨论】:

    猜你喜欢
    • 2014-10-20
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    • 1970-01-01
    • 2011-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多