Невозможно установить изображение при настройке кнопок расширения клавиатуры (Swift) - PullRequest
0 голосов
/ 30 июня 2019

Я пытаюсь создать собственное расширение клавиатуры с помощью Swift для устройств iOS. Но теперь у меня возникли проблемы при настройке кнопок расширения клавиатуры. Вот мои коды:

class KeyboardViewController: UIInputViewController {
      var qButton: UIButton = {
      var button = UIButton(type: .system)
      button.translatesAutoresizingMaskIntoConstraints = false
      button.backgroundColor = UIColor(white: 1.0, alpha: 1.0)
      button.setTitleColor(UIColor.black, for: .normal)
      button.layer.cornerRadius = 5
      button.titleLabel?.font = UIFont.systemFont(ofSize: 22, weight: .regular)
      button.setImage(UIImage(named: "q")?.withRenderingMode(.alwaysOriginal), for: .normal)
      button.addTarget(self, action: #selector(keyPressed), for: .touchUpInside)
        return button
    }()

   var firstStackRow: UIStackView = {
        var firstStackRow = UIStackView()
        firstStackRow.translatesAutoresizingMaskIntoConstraints = false
        firstStackRow.axis = .horizontal
        firstStackRow.distribution = .fillEqually
        firstStackRow.spacing = 6
        firstStackRow.backgroundColor = .lightGray
        return firstStackRow
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

    self.view.addSubview(firstStackRow)
    firstStackRow.translatesAutoresizingMaskIntoConstraints = false
    firstStackRow.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 3).isActive = true
    firstStackRow.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: -3).isActive = true
    firstStackRow.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 10.5).isActive = true
    firstStackRow.heightAnchor.constraint(equalTo: self.view.heightAnchor, multiplier: 1/4, constant: -12).isActive = true


    firstStackRow.addArrangedSubview(qButton)
    qButton.heightAnchor.constraint(equalTo: firstStackRow.heightAnchor).isActive = true
    qButton.topAnchor.constraint(equalTo: firstStackRow.topAnchor).isActive = true


    }
}

Но, похоже, кнопка "q" не может отобразить изображение. Не уверен, что там не так. Любые идеи будут оценены.

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...