Я недавно задал вопрос here, где хотел бы разобраться, как изменить UIColor
. Я следовал рекомендациям @Dorian Roy, который был очень чистым, и он хорошо работал для моих нужд. Хотя мой конкретный вопрос ранее был вокруг одной кнопки, я хотел бы знать, как изменить несколько UIBUttons
. Это можно сделать? Моя мысль была бы subclass
a UIButton
и инициализировать его, чтобы автоматически изменить его цвет image
. Я не могу понять, как это сделать.Как изменить цвет кнопок кнопки в Swift3?
Вот как я сейчас выполняю это действие, и я ищу более элегантное решение.
private func changeBtnColors() {
let ccStencil = creditCardBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
let planeStencil = planeBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
let towelStencil = towelBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
let carStencil = carBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
let trainStencil = trainBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
let graphStencil = graphBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
creditCardBtn.setImage(ccStencil, for: .normal)
planeBtn.setImage(planeStencil, for: .normal)
towelBtn.setImage(towelStencil, for: .normal)
carBtn.setImage(carStencil, for: .normal)
trainBtn.setImage(trainStencil, for: .normal)
graphBtn.setImage(graphStencil, for: .normal)
creditCardBtn.tintColor = UIColor.white
planeBtn.tintColor = UIColor.white
towelBtn.tintColor = UIColor.white
carBtn.tintColor = UIColor.white
trainBtn.tintColor = UIColor.white
graphBtn.tintColor = UIColor.white
}