MCEmojiPicker Documentation

repository·main·Indexed 19 days ago

https://github.com/izyumkin/mcemojipicker

A customizable library for implementing a macOS-style emoji picker popover in iOS applications. Supports UIKit via MCEmojiPickerViewController and SwiftUI via the .emojiPicker view modifier. Installable via CocoaPods, Swift Package Manager, or manual integration.

Tokens
1K
Snippets
5
Records
7
Agent score
15%

What's inside MCEmojiPicker

  1. Quick Start: Presenting the Emoji Picker in UIKit

    main

    To use the emoji picker in a UIKit application, instantiate MCEmojiPickerViewController, set its delegate and sourceView, and present it from a view controller.

    @objc private func selectEmojiAction(_ sender: UIButton) {
        let viewController = MCEmojiPickerViewController()
        viewController.delegate = self
        viewController.sourceView = sender
        present(viewController, animated: true)
    }
    
    // Handle the selection in the delegate method
    extension ViewController: MCEmojiPickerDelegate {
        func didGetEmoji(emoji: String) {
            emojiButton.setTitle(emoji, for: .normal)
        }
    }
  2. Use MCEmojiPicker in SwiftUI

    main

    You can use MCEmojiPicker in SwiftUI using the .emojiPicker view modifier or by interacting directly with MCEmojiPickerRepresentableController.

    // Using the view modifier
    Button(selectedEmoji) {
        isPresented.toggle()
    }.emojiPicker(
        isPresented: $isPresented,
        selectedEmoji: $selectedEmoji
    )
    
    // Using the Representable Controller directly
    MCEmojiPickerRepresentableController(
        isPresented: $isPresented,
        selectedEmoji: $selectedEmoji,
        arrowDirection: .up,
        customHeight: 380.0,
        horizontalInset: .zero,
        isDismissAfterChoosing: true,
        selectedEmojiCategoryTintColor: .systemBlue,
        feedBackGeneratorStyle: .light
    )
  3. Configure MCEmojiPickerViewController properties

    main

    You can customize the appearance and behavior of MCEmojiPickerViewController using the following properties:

    • selectedEmojiCategoryTintColor: The color for the selected emoji category. Default is .systemBlue.
    • arrowDirection: The direction of the popover arrow. Default is .up.
    • horizontalInset: The inset from the sourceView border. Default is 0.
    • isDismissAfterChoosing: Whether to dismiss the picker after an emoji is selected. Default is true.
    • customHeight: A custom height for the picker. Default is nil.
    • feedBackGeneratorStyle: The haptic feedback style. Default is .light. Set to nil to disable feedback.
    viewController.selectedEmojiCategoryTintColor = .systemRed
    viewController.arrowDirection = .up
    viewController.horizontalInset = 0
    viewController.isDismissAfterChoosing = true
    viewController.customHeight = 300
    viewController.feedBackGeneratorStyle = .soft