2017-04-22 71 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