ISEmojiView Documentation

repository·master·Indexed 20 days ago

https://github.com/isaced/isemojiview

An emoji keyboard for iOS written in Swift. ISEmojiView supports custom emojis, multiple skin tones, categories, and recent emojis, providing integration for both UIKit and SwiftUI. It includes the EmojiViewDelegate protocol for handling user interactions and KeyboardSettings for customizing keyboard behavior and appearance.

Tokens
1.5K
Snippets
7
Records
8
Agent score
19%

What's inside ISEmojiView

  1. Install ISEmojiView via CocoaPods or Carthage

    master

    CocoaPods

    For Swift projects:

    pod 'ISEmojiView'

    Note: The Objective-C version is no longer maintained. To use the legacy version, use pod 'ISEmojiView', '0.0.1'.

    Carthage

    Add the following to your Cartfile:

    github "isaced/ISEmojiView"
  2. Install ISEmojiView

    master

    You can install ISEmojiView using Swift Package Manager, CocoaPods, or Carthage.

    #### Swift Package Manager
    In `Package.swift`:
    ```swift
    .package(name: "ISEmojiView", url: "https://github.com/isaced/ISEmojiView.git", .upToNextMinor(from: "0.3.0")),

    Cocoapods

    # Swift
    pod 'ISEmojiView'
    
    # Objective-C (Deprecated)
    pod 'ISEmojiView', '0.0.1'

    Carthage

    github "isaced/ISEmojiView"
  3. Install ISEmojiView via Swift Package Manager

    master

    To add ISEmojiView to your project using Swift Package Manager, add the following dependency to your Package.swift:

    .package(name: "ISEmojiView", url: "https://github.com/isaced/ISEmojiView.git", .upToNextMinor(from: "0.3.0")),

    Alternatively, in Xcode:

    1. Go to File > Swift Packages > Add Package Dependency.
    2. Search for https://github.com/isaced/ISEmojiView.git.
    3. Select the version rule Up to Next Major starting from 0.3.0.
  4. Configure KeyboardSettings

    master

    Use the KeyboardSettings class to customize the behavior and appearance of the emoji keyboard.

    Available properties:

    • bottomType: Sets the bottom view type. Options are .pageControl (default) and .categories.
    • customEmojis: A list of custom emojis using the EmojiCategory class.
    • isShowPopPreview: Determines if long-pressing an emoji shows a skin tone selection popover (similar to iOS 10). Defaults to true.
    • countOfRecentsEmojis: The maximum number of recent emojis to show. Set to 0 to disable the "Recents" feature. Defaults to 50.
    • needToShowAbcButton: A boolean indicating whether to show the button to switch back to the standard keyboard (available in .categories mode).
  5. Initialize EmojiView in Swift

    master

    To use the emoji keyboard, import ISEmojiView, create a KeyboardSettings instance, and initialize an EmojiView. You typically assign the EmojiView to a UITextView's inputView property.

    import ISEmojiView
    
    let keyboardSettings = KeyboardSettings(bottomType: .categories)
    let emojiView = EmojiView(keyboardSettings: keyboardSettings)
    emojiView.translatesAutoresizingMaskIntoConstraints = false
    emojiView.delegate = self
    textView.inputView = emojiView
  6. Initialize EmojiView

    master

    To use the emoji keyboard, create an instance of EmojiView with a KeyboardSettings object and assign it to a text view's inputView.

    let keyboardSettings = KeyboardSettings(bottomType: .categories)
    let emojiView = EmojiView(keyboardSettings: keyboardSettings)
    emojiView.translatesAutoresizingMaskIntoConstraints = false
    emojiView.delegate = self
    textView.inputView = emojiView
  7. Implement EmojiViewDelegate

    master

    To handle user interactions like emoji selection, keyboard switching, or deletion, implement the EmojiViewDelegate protocol.

    Key methods include:

    • emojiViewDidSelectEmoji(_:emojiView:): Called when an emoji is tapped.
    • emojiViewDidPressChangeKeyboardButton(_:): Called when the button to switch back to the standard keyboard is pressed.
    • emojiViewDidPressDeleteBackwardButton(_:): Called when the delete button is pressed.
    • emojiViewDidPressDismissKeyboardButton(_:): Called when the dismiss button is pressed.
    // 回调:点击某个 Emoji 表情的
    func emojiViewDidSelectEmoji(_ emoji: String, emojiView: EmojiView) {
        textView.insertText(emoji)
    }
    
    // 回调:点击切换键盘按钮
    func emojiViewDidPressChangeKeyboardButton(_ emojiView: EmojiView) {
        textView.inputView = nil
        textView.keyboardType = .default
        textView.reloadInputViews()
    }
        
    // 回调:点击删除按钮
    func emojiViewDidPressDeleteBackwardButton(_ emojiView: EmojiView) {
        textView.deleteBackward()
    }
    
    // 回调:点击隐藏按钮
    func emojiViewDidPressDismissKeyboardButton(_ emojiView: EmojiView) {
        textView.resignFirstResponder()
    }
  8. Use EmojiView in SwiftUI

    master

    ISEmojiView provides a SwiftUI view called EmojiView_SwiftUI(). Note that it does not work on macOS SwiftUI natively.

    You can pass the following parameters to EmojiView_SwiftUI for customization:

    • countOfRecentsEmojis
    • needToShowAbcButton
    • needToShowDeleteButton
    • updateRecentEmojiImmediately
    import ISEmojiView
    
    EmojiView_SwiftUI()
        .frame(width: 300, height: 500)
        .padding()