Добавить Toolbar программно, с отступами, кнопками и настроить его (Add UIToolBar, toolbar programmatically from navigation controller) - Swift 5, Xcode 13
Индивидуальное, дистанционное обучение программированию
подробнее
// Изменить фон корневого view
view.backgroundColor = .red
// Настройка UIToolbar
let appearance = UIToolbarAppearance()
appearance.configureWithOpaqueBackground()
// Изменить цвет фона
appearance.
backgroundColor = .white
// Изменить цвет кнопок
navigationController?.toolbar.tintColor = .black
navigationController?.
toolbar.
standardAppearance = appearance
navigationController?.toolbar.scrollEdgeAppearance = appearance
// Массив для кнопок
var buttons = [UIBarButtonItem]()
// Кнопка
buttons.append(
UIBarButtonItem(barButtonSystemItem: .
camera, target:
self, action:
nil) )
// Отступ
buttons.append(
UIBarButtonItem(barButtonSystemItem: .
flexibleSpace, target:
self, action:
nil) )
// Кнопка
buttons.append(
UIBarButtonItem(barButtonSystemItem: .
add, target:
self, action:
nil) )
// Отступ
buttons.append(
UIBarButtonItem(barButtonSystemItem: .
flexibleSpace, target:
self, action:
nil) )
// Кнопка
buttons.append(
UIBarButtonItem(barButtonSystemItem: .
compose, target:
self, action:
nil) )
// Добавляем кнопки и отступы
self.toolbarItems = buttons
// Показать toolBar
navigationController?.setToolbarHidden(false, animated: true)
Возврат к списку