2017-05-03 1 views
-1

iPad에서 성공적으로 실행되는 아래 코드가 있습니다.이미지를 표시하는 버튼이있는 IOS의 사용자 정의 키보드

func setupLockPinSection() { 

     let keys = ["1", "2","3", "4","5", "6","7", "8","9", "0", "Clear", "Done"] 
     let kbFrame = CGRect(x: 0, y: 0, width: view.frame.width, height: 400) 

     if let customKeyboard = Bundle.main.loadNibNamed("MACustomKeyboard", owner: self, options: nil)?.first as? MACustomKeyboard { 

      customKeyboard.frame = kbFrame 
      customKeyboard.setKeyboardButtons(keys) 

      lockPin1.inputView = customKeyboard 

      //Number Tapped 
      customKeyboard.numberTappedBlock = { [weak self] view, text in 

       if let textFieldText = self?.lockPin1.text, let t = text { 
        self?.lockPin1.text = textFieldText + t 
       } 

      } 

      //Done button Tapped 
      customKeyboard.doneTappedBlock = { [weak self] view in 
       self?.lockPin1.resignFirstResponder() 
      } 

      //Clear Button Tapped 
      customKeyboard.clearTappedBlock = { [weak self] view in 

       if let text = self?.lockPin1.text, text.characters.count > 0 { 
        self?.lockPin1.text = text.substring(to: text.index(text.endIndex, offsetBy: -1)) 
       } 

      } 

     } 

     if let customKeyboard = Bundle.main.loadNibNamed("MACustomKeyboard", owner: self, options: nil)?.first as? MACustomKeyboard { 

      customKeyboard.frame = kbFrame 
      customKeyboard.setKeyboardButtons(keys) 

      lockPin2.inputView = customKeyboard 

      //Number Tapped 
      customKeyboard.numberTappedBlock = { [weak self] view, text in 

       if let textFieldText = self?.lockPin2.text, let t = text { 
        self?.lockPin2.text = textFieldText + t 
       } 

      } 

      //Done button Tapped 
      customKeyboard.doneTappedBlock = { [weak self] view in 
       self?.lockPin2.resignFirstResponder() 
      } 

      //Clear Button Tapped 
      customKeyboard.clearTappedBlock = { [weak self] view in 

       if let text = self?.lockPin2.text, text.characters.count > 0 { 
        self?.lockPin2.text = text.substring(to: text.index(text.endIndex, offsetBy: -1)) 
       } 

      } 

     } 

     lockPin1.text = UserDefaults.standard.string(forKey: "lockPin") 
     lockPin2.text = UserDefaults.standard.string(forKey: "lockPin") 

    } 

이 나는 ​​화상을 표시 (숨어 키보드 버튼, 지우기 버튼)와 아이폰 OS의 기본 키보드에있는 것과 같은 명확하고 완료 버튼을 만들고 싶어. 나는 자물쇠 핀 기능을 위해 숫자 만 사용하고 iPad에서는 허용하지 않기 때문에이 작업을 수행하려고합니다. 그러므로 나는 그것을 사용자 정의 된 키보드로 만들 필요가있다.

+0

그래서 무엇이 문제입니까? :) – d4Rk

+0

@ d4Rk, 방금 아래 문제로 이미지가 추가로 게시되었습니다. 당신이 그것을 줄 수 있다면 제게 해결책을 제안하십시오. 감사합니다. – habed

답변

관련 문제