QMUIEmotionView

@interface QMUIEmotionView
    : UIView <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

表情控件,支持任意表情的展示,每个表情以相同的大小显示。

使用方式:

  • 通过initWithFrame:初始化,如果面板高度不变,建议在init时就设置好,若最终布局以父类的layoutSubviews为准,则也可通过init方法初始化,再在layoutSubviews里计算布局
  • 通过调整paddingInPageemotionSize等变量来自定义UI
  • 通过emotions设置要展示的表情
  • 通过didSelectEmotionBlock设置选中表情时的回调,通过didSelectDeleteButtonBlock来响应面板内的删除按钮
  • sendButton添加addTarget:action:forState:事件,从而触发发送逻辑

本控件支持通过UIAppearance设置全局的默认样式。若要修改控件内的UIPageControl的样式,可通过[UIPageControl appearanceWhenContainedInInstancesOfClasses:@[[QMUIEmotionView class]]]的方式来修改。

  • 要展示的所有表情

    Declaration

    Objective-C

    @property (nonatomic, copy) NSArray<QMUIEmotion *> *emotions;

    Swift

    var emotions: [QMUIEmotion]! { get set }
  • 选中表情时的回调 @argv index 被选中的表情在emotions里的索引 @argv emotion 被选中的表情对应的QMUIEmotion对象

    See

    QMUIEmotion

    Declaration

    Objective-C

    @property (nonatomic, copy) void (^)(NSInteger, QMUIEmotion *) didSelectEmotionBlock;

    Swift

    var didSelectEmotionBlock: ((Int, QMUIEmotion?) -> Void)! { get set }
  • 删除按钮的点击事件回调

    Declaration

    Objective-C

    @property (nonatomic, copy) void (^)(void) didSelectDeleteButtonBlock;

    Swift

    var didSelectDeleteButtonBlock: (() -> Void)! { get set }
  • 用于展示表情面板的横向滚动collectionView,布局撑满整个控件

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) UICollectionView *collectionView;

    Swift

    var collectionView: UICollectionView! { get }
  • 用于横向按页滚动的collectionViewLayout

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) UICollectionViewFlowLayout *collectionViewLayout;

    Swift

    var collectionViewLayout: UICollectionViewFlowLayout! { get }
  • 控件底部的分页控件,可点击切换表情页面

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) UIPageControl *pageControl;

    Swift

    var pageControl: UIPageControl! { get }
  • 控件右下角的发送按钮

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) QMUIButton *sendButton;

    Swift

    var sendButton: QMUIButton! { get }
  • 每一页表情的上下左右padding,默认为{18, 18, 65, 18}

    Declaration

    Objective-C

    @property (nonatomic) UIEdgeInsets paddingInPage;

    Swift

    var paddingInPage: UIEdgeInsets { get set }
  • 每一页表情允许的最大行数,默认为4

    Declaration

    Objective-C

    @property (nonatomic) NSInteger numberOfRowsPerPage;

    Swift

    var numberOfRowsPerPage: Int { get set }
  • 表情的图片大小,不管QMUIEmotion.image.size多大,都会被缩放到emotionSize里显示,默认为{30, 30}

    Declaration

    Objective-C

    @property (nonatomic) CGSize emotionSize;

    Swift

    var emotionSize: CGSize { get set }
  • 表情点击时的背景遮罩相对于emotionSize往外拓展的区域,负值表示遮罩比表情还大,正值表示遮罩比表情还小,默认为{-3, -3, -3, -3}

    Declaration

    Objective-C

    @property (nonatomic) UIEdgeInsets emotionSelectedBackgroundExtension;

    Swift

    var emotionSelectedBackgroundExtension: UIEdgeInsets { get set }
  • 表情与表情之间的最小水平间距,默认为10

    Declaration

    Objective-C

    @property (nonatomic) CGFloat minimumEmotionHorizontalSpacing;

    Swift

    var minimumEmotionHorizontalSpacing: CGFloat { get set }
  • 表情面板右下角的删除按钮的图片,默认为[QMUIHelper imageWithName:@"QMUI_emotion_delete"]

    Declaration

    Objective-C

    @property (nonatomic, strong) UIImage *deleteButtonImage;

    Swift

    var deleteButtonImage: UIImage! { get set }
  • 发送按钮的文字样式,默认为{NSFontAttributeName: UIFontMake(15), NSForegroundColorAttributeName: UIColorWhite}

    Declaration

    Objective-C

    @property (nonatomic, strong) NSDictionary *sendButtonTitleAttributes;

    Swift

    var sendButtonTitleAttributes: [AnyHashable : Any]! { get set }
  • 发送按钮的背景色,默认为UIColorBlue

    Declaration

    Objective-C

    @property (nonatomic, strong) UIColor *sendButtonBackgroundColor;

    Swift

    var sendButtonBackgroundColor: UIColor! { get set }
  • 发送按钮的圆角大小,默认为4

    Declaration

    Objective-C

    @property (nonatomic) CGFloat sendButtonCornerRadius;

    Swift

    var sendButtonCornerRadius: CGFloat { get set }
  • 发送按钮布局时的外边距,相对于控件右下角。仅right/bottom有效,默认为{0, 0, 16, 16}

    Declaration

    Objective-C

    @property (nonatomic) UIEdgeInsets sendButtonMargins;

    Swift

    var sendButtonMargins: UIEdgeInsets { get set }
  • 分页控件距离底部的间距,默认为22

    Declaration

    Objective-C

    @property (nonatomic) CGFloat pageControlMarginBottom;

    Swift

    var pageControlMarginBottom: CGFloat { get set }