2017-04-22 100 views
-3

我是新的快速编程,我试图制作一个钢琴应用程序。有谁知道豪特在Swift中的按钮边框? 我在互联网上搜索,但所有的教程都是针对老版本的Swift,它不再工作。快速按钮的轮廓

+0

请搜索。在[这些搜索结果](http://stackoverflow.com/search?page=1&tab=Relevance&q=%5bswift%5d%20uibutton%20border)中的第一次击中应该工作。 – rmaddy

回答

0

尝试这个

  button.layer.borderWidth = 1.0 
      button.layer.borderColor = UIColor.whiteColor().CGColor 
      button.layer.cornerRadius = 5.0 
      button.clipsToBounds = true 

您可以轻松地更改按钮属性,如(边框宽度,边框颜色,cornerRadius)值

-1

这里是SWIFT 3

button.layer.borderWidth = 1.0 
button.layer.borderColor = UIColor.white.cgColor 
// if you want corners to be rounded you can use the corner radus 
button.layer.cornerRadius = 4.0 
// if you're setting background image to the button and it happens to be not clipped then you can use 
button.clipsToBounds = true 
0

的UIButton继承的代码UIControl和UIControl从 继承UIView。 UIView包含用于渲染的CALayer(核心动画层)。 https://developer.apple.com/reference/quartzcore/calayer

import UIKit 
import PlaygroundSupport 

let button = UIButton(type: .custom) 
button.frame = CGRect(x: 0, y: 0, width: 100, height: 100) 
button.backgroundColor = .red 
button.layer.borderWidth = 2.0 
button.layer.borderColor = UIColor.green.cgColor 

PlaygroundPage.current.liveView = button