专业java、php、iOS、C++、网页设计、平面设计、网络营销、游戏开发、前端与移动开发培训机构

表情键盘分析

  • 表情键盘 其实也是一个 自定义view.自定义的表情键盘分为2块.上面是 UICollectionView 下面是 UIView 里面放按钮
  • 表情键盘是一个相对独立的功能,在项目开发中,可以把相对独立的功能单独建立一个工程,方便开发和测试.等功能开发完成的时候在整合到项目中

新建表情键盘项目

  • 新建表情键盘项目
  • 新建 HMEmoticonKeyboard 文件夹
  • HMEmoticonKeyboard 文件夹里面新建 HMEmoticonKeyboard.swift 继承自 UIView, 作为表情键盘自定义 view,并使用 XIB 来描述这个键盘
  • Main.storyboard 添加 textView 控件,并关联到 ViewController
  • 设置 keyboardtextViewinputView

    override func viewDidLoad() {
      super.viewDidLoad()
    
      let keyboard = Bundle.main.loadNibNamed("HMEmoticonKeyboard", owner: nil, options: nil)?.last as! HMEmoticonKeyboard
    
      textView.inputView = keyboard
    
      textView.becomeFirstResponder()
    }
    

results matching ""

    No results matching ""