让多个按钮共享相同外观的最佳做法是什么?
现在我在这样的循环中创建这些按钮:
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)
}
什么是Swift方式做这些事情?子类UIButton?或者添加一些初始化方法作为扩展名?