Custom Keyboard InputAccessoryView not visible in iOS 11

前端 未结 7 1961
攒了一身酷
攒了一身酷 2021-02-18 21:30

I have implemented Custom input accessory view it was working fine till iOS 10.3.1. But it\'s not visible in iOS 11 beta.

Have anyone experience this issue?

7条回答
  •  无人共我
    2021-02-18 21:57

    Swift 4 solution

    let toolBarRect = CGRect(x: 0, y: 0, width: self.view.frame.width, height: 44)
    let toolBar = UIView(frame: toolBarRect)
    toolBar.backgroundColor = .lightGray
    
    let nextButton = UIButton()
    nextButton.setTitleColor(.black, for: .normal)
    nextButton.setTitle("Next", for: .normal)
    nextButton.addTarget(self, action: #selector(self.onNextButtonTouch), for: .touchUpInside)
    nextButton.translatesAutoresizingMaskIntoConstraints = false
    toolBar.addSubview(nextButton)
    
    NSLayoutConstraint.activate(
        [
            nextButton.heightAnchor.constraint(equalToConstant: Constants.keyboardToolBarHeight),
            nextButton.trailingAnchor.constraint(equalTo: toolBar.trailingAnchor, constant: -16),
            nextButton.centerYAnchor.constraint(equalTo: toolBar.centerYAnchor, constant: 0)
        ]
    )
    
    self.yourTextField.inputAccessoryView = toolBar
    

提交回复
热议问题