0
讓多個按鈕共享相同外觀的最佳做法是什麼?讓多個UIButton共享相同外觀的最佳方法
現在,我在這樣的循環創建這些按鈕:
for i in 0..<10{
let button = UIButton()
button.setTitle(String(i), for: .normal)
button.backgroundColor = #colorLiteral(red: 0.3137254902, green: 0.2745098039, blue: 0.2745098039, alpha: 0.5977632705)
numberButtons.append(button)
button.layer.borderColor = #colorLiteral(red: 0.04296875, green: 0.04296875, blue: 0.04296875, alpha: 0.5).cgColor
button.layer.borderWidth = 1.0
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
}
什麼是斯威夫特的方式做這樣的事情?子類UIButton?或者添加一些初始化方法作爲擴展名?
你看過UIAppearance的功能https://developer.apple.com/reference/uikit/uiappearance –