Последняя часть кода, который вы процитировали, находится в методе setUpButton
:
fileprivate func setupButton(index i:Int) -> UIButton{
if buttonHeight == 0 {buttonHeight = CGFloat(Int(deviceHeight * 0.07))}
let finButton: UIButton
if let button: UIButton = self.buttonInit?(i) {
finButton = button
}else {
let button = UIButton(type: .custom)
button.setTitleColor(button.tintColor, for: [])
button.layer.borderColor = button.tintColor.cgColor
button.layer.borderWidth = 1
button.layer.cornerRadius = buttonHeight/2
finButton = button
}
Этот метод вызывается здесь:
open func addAction(_ action: AZDialogAction){
actions.append(action)
if buttonsStackView != nil{
let button = setupButton(index: actions.count-1)
self.buttonsStackView.addArrangedSubview(button)
//button.frame = buttonsStackView.bounds
button.center = CGPoint(x: buttonsStackView.bounds.midX,y: buttonsStackView.bounds.maxY)
animateStackView()
}
}
Из этого мы можем видеть, что buttonInit
, кажется, используется, чтобы позволить пользователю библиотеки указать, какую кнопку он хочет использовать в качестве кнопок действия.Еще одним свидетельством является то, что buttonInit
объявлен open
, поэтому, скорее всего, это должен быть установлен клиентский код, а не AZDialogViewController
.
Plus, README
файл показал это использование:
Использовать пользовательский подкласс UIButton:
dialog.buttonInit = { index in
//set a custom button only for the first index
return index == 0 ? HighlightableButton() : nil
}
Итак, чтобы ответить на ваш вопрос,if
ветвь будет выполнена, если вы установите buttonInit
.