iOS 自定义键盘+表情布局实现

本节主要内容:

1.自定义键盘--将工具栏添加到键盘上,并实现切换
2.实现进入到系统相册选取图片
3.实现表情布局
4.实现系统键盘和表情视图之间的切换
5.表情消息的追加

一、*自定义键盘

创建子视图,为系统键盘添加工具栏。例子中创建了textView和一个带有5个button的编辑工具栏

#pragma mark - 创建子视图
- (void)creactSubView{

    //1 添加_textView
    _textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-50)];
    _textView.backgroundColor = [UIColor clearColor];
    _textView.font = [UIFont systemFontOfSize:15.0];
    [_textView becomeFirstResponder];
    [self.view addSubview:_textView];

    //2 编辑栏
    _editorView = [[UIView alloc] initWithFrame:CGRectMake(0, _textView.bottom, kScreenWidth, 50)];
    _editorView.backgroundColor = [UIColor clearColor];
    //***将_editorView添加到系统键盘上,利用下面的inputAccessoryView方法
    _textView.inputAccessoryView = _editorView;
    //添加5个按钮
    NSArray *imgArr = @[
                        @"compose_toolbar_1.png",
                        @"compose_toolbar_3.png",
                        @"compose_toolbar_4.png",
                        @"compose_toolbar_5.png",
                        @"compose_toolbar_6.png"
                        ];
    CGFloat btnWidth = kScreenWidth/5;

    for (int i = 0; i<imgArr.count; i++) {
        ThemeButton *button = [[ThemeButton alloc] initWithFrame:CGRectMake(btnWidth*i, 5, btnWidth, 40)];

        button.imageName = imgArr[i];

        [button addTarget:self action:@selector(pressAction:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = 1000+i;

        [_editorView addSubview:button];
    }
}

二、*进入系统相册选取图片

按钮1的响应事件—实现进入系统相册选取图片(单张)

switch (button.tag - 1000) {
        case 0:
            NSLog(@"点击第一个按钮");
        {
            //由底部弹出的弹窗
            UIAlertController *alter = [UIAlertController alertControllerWithTitle:@"选取图片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];

            UIAlertAction *action = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

                //选取相册
                UIImagePickerController *picker = [[UIImagePickerController alloc] init];

                picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
                picker.delegate = self;
                //模态视图 弹出相册
                [self presentViewController:picker animated:YES completion:nil];
            }];

            [alter addAction:action];

            [self presentViewController:alter animated:YES completion:nil];

        }
            break;

三、*表情布局

要实现的效果:

所有表情分成几页,每页按照4行7列进行排列,点击任意表情会出现该表情的放大镜,放大镜上有该表情和文字。能够实现页面的滑动。

思路:

1.数据处理

从plist文件中取出所有文件,将其存放进一个大的数组中,将这个大数组分割成28个数据一组的小数组,小数组的数量将会对应页面的数量。而在每个小数组里面,这28个数据将会按照4行7列进行排列。

2.页面处理

由外至内视图分别是:UIView->UIScrolleView->UIView->UIImageView(表情视图和选中视图)

代码:

FaceView

.h文件

#import <UIKit/UIKit.h>
#import "UIViewExt.h"

@interface FaceView : UIView
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值