Как установить заголовок под MDCBottomAppBarView, ведущий, трейлинг и центральная кнопка? - PullRequest
1 голос
/ 21 января 2020

Я использую MDCBottomAppBarView, который я нашел здесь https://material.io/develop/ios/components/bottomappbar/. Теперь меня беспокоит то, как я могу установить заголовок под этими кнопками. В моем приложении я должен установить заголовок под этими кнопками.

Заранее спасибо.

РЕДАКТИРОВАТЬ

У меня получилось установить заголовок ведущая и конечная кнопка MDCBottomAppBarView, как показано ниже, но все еще не может установить заголовок центральной кнопки MDCBottomAppBarView.

func setUpBottomView() {

    bottomBarView.autoresizingMask = [ .flexibleWidth, .flexibleTopMargin ]
    view.addSubview(bottomBarView)

    // Bottom bar set up
    bottomBarView.floatingButton.setImage(#imageLiteral(resourceName: "ic_niddle"), for: .normal)
    bottomBarView.floatingButton.setBackgroundColor(UIColor.init(red: 250, green: 50, blue: 51, alpha: 1.0))
    bottomBarView.floatingButton.addTarget(self, action: #selector(centerBtnTapped), for: .touchUpInside)

    var imgNameLeft = "noun_Mail_8984"
    var leftBtnTitle = "Invitation"

    let buttonLeading = UIButton(type: .system)
    buttonLeading.setImage(UIImage(named: imgNameLeft), for: .normal)
    buttonLeading.setTitle(leftBtnTitle, for: .normal)
    buttonLeading.titleLabel?.font = UIFont().RobotoRegular(size: 13.0)
    buttonLeading.sizeToFit()
    buttonLeading.centerVertically()
    buttonLeading.addTarget(self, action: #selector(leftBtnTapped), for: .touchUpInside)
    let barButtonLeadingItem = UIBarButtonItem(customView: buttonLeading)

    let buttonTrailing = UIButton(type: .system)
    buttonTrailing.setImage(UIImage(named: "Group 1275"), for: .normal)
    buttonTrailing.setTitle("Chat", for: .normal)
    buttonTrailing.titleLabel?.font = UIFont().RobotoRegular(size: 13.0)
    buttonTrailing.sizeToFit()
    buttonTrailing.centerVertically()
    buttonTrailing.addTarget(self, action: #selector(rightBtnTapped), for: .touchUpInside)
    let barButtonTrailingItem = UIBarButtonItem(customView: buttonTrailing)

    bottomBarView.leadingBarButtonItems = [ barButtonLeadingItem ]
    bottomBarView.trailingBarButtonItems = [ barButtonTrailingItem ]
}
extension UIButton {

    func centerVertically(padding: CGFloat = 5.0) {
        guard
            let imageViewSize = self.imageView?.frame.size,
            let titleLabelSize = self.titleLabel?.frame.size else {
            return
        }

        let totalHeight = imageViewSize.height + titleLabelSize.height + padding

        self.imageEdgeInsets = UIEdgeInsets(
            top: -(totalHeight - imageViewSize.height),
            left: 0.0,
            bottom: 0.0,
            right: -titleLabelSize.width
        )

        self.titleEdgeInsets = UIEdgeInsets(
            top: 0.0,
            left: -imageViewSize.width,
            bottom: -(totalHeight - titleLabelSize.height),
            right: 0.0
        )

        let inset = (self.frame.size.height - totalHeight) / 2
        self.contentEdgeInsets = UIEdgeInsets(
            top: inset + 5,
            left: 0.0,
            bottom: inset,
            right: 0.0
        )
    }
}
...