按钮边框与Swift的透明背景

前端之家收集整理的这篇文章主要介绍了按钮边框与Swift的透明背景前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使UIButton边框看起来像下面的图像(“入门”)按钮与透明背景?

如何使用故事板或如何以编程方式实现这一点?

将backgroundColor设置为clearColor使按钮变得透明.尝试下面的代码.您可以根据需要配置和更改borderAlpha,cornerRadius和颜色.
  1. let borderAlpha : CGFloat = 0.7
  2. let cornerRadius : CGFloat = 5.0
  3.  
  4. button.frame = CGRectMake(100,100,200,40)
  5. button.setTitle("Get Started",forState: UIControlState.Normal)
  6. button.setTitleColor(UIColor.whiteColor(),forState: UIControlState.Normal)
  7. button.backgroundColor = UIColor.clearColor()
  8. button.layer.borderWidth = 1.0
  9. button.layer.borderColor = UIColor(white: 1.0,alpha: borderAlpha).CGColor
  10. button.layer.cornerRadius = cornerRadius

猜你在找的Swift相关文章