В настоящее время я реализую приложение с настраиваемой панелью инструментов. Панель инструментов я добавлю программно. Я хочу, чтобы панель инструментов отображалась с изображением и текстом, например:
К сожалению, написанная мной панель инструментов выглядит следующим образом:
![enter image description here](https://i.stack.imgur.com/l6t29.png)
и я не совсем уверен, почему это не работает.
Код, который я написал, выглядит следующим образом:
self.navigationController?.isToolbarHidden = false
let customButton : UIButton = UIButton(type: .custom)
customButton.setImage(UIImage(named: "Home"), for: .normal)
customButton.imageView?.contentMode = .scaleAspectFit
let customButton1 : UIButton = UIButton(type: .custom)
customButton1.setImage(UIImage(named: "Account"), for: .normal)
customButton1.imageView?.contentMode = .scaleAspectFit
let customButton2 : UIButton = UIButton(type: .custom)
customButton2.setImage((UIImage(named: "Ball")), for: .normal)
customButton2.imageView?.contentMode = .scaleAspectFit
customButton.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
customButton1.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
customButton2.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
let customBarButtonItem = UIBarButtonItem(customView: customButton as UIView)
let customBarButtonItem1 = UIBarButtonItem(customView: customButton1 as UIView)
let customBarButtonItem2 = UIBarButtonItem(customView: customButton2 as UIView)
var items = [UIBarButtonItem]()
items.append( UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil))
items.append( customBarButtonItem)
items.append( UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil) )
items.append( customBarButtonItem1)
items.append( UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil) )
items.append( customBarButtonItem2)
self.toolbarItems = items
Я знаю, что код выглядит ужасно но я просто хочу заставить его работать, и никакое решение, которое я нашел, не сработало для меня.
Также, возможно, если кто-то знает хороший учебник о том, как создавать панели инструментов программно, я был бы признателен за ссылку. :)