代码未上,效果先行
当然,底部的按钮是可以灵活配置的,最多三个(左边一个,右边两个)
how to use
- (void)setupUI
{
CGFloat screenW = [UIScreen mainScreen].bounds.size.width;
CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
self.inputView = [DifferInputView InputViewWithFrame:CGRectMake(0, screenH - 44, screenW, 44) limitLength:100 leftImage:@"icon_like_down" middleImage:nil rightImage:@"icon_like_down" buttonClickBlock:^(NSInteger index) {
NSLog(@"%ld",index);
// index 0:点击了左边的按钮,即使左边的图片传空,不显示左边的按钮,index为0也表示点击了左边的按钮,一次内推,1表示点击了中间的按钮,2表示点击了右边的按钮
} returnClick:^(NSString *result) { //点击键盘上的return按钮
NSLog(@"%@",result);
self.textResult.text = result;
}];
[self.view addSubview:self.inputView];
}
最后看一下头文件
#import <UIKit/UIKit.h>
typedef void(^ButtonClickBlock)(NSInteger index);
typedef void(^ReturnClickBlock)(NSString *result);
@interface DifferInputView : UIView
/*
1.注意命名要求,@"leftImageName" 高亮则为:@"leftImageName_pre" 目的是为了少传几个参数。若传nil,则表示隐藏该按钮
2.限制 字符数 为-1,则表示 没有限制
3.textview的returnType 为send
*/
+ (instancetype)InputViewWithFrame:(CGRect)frame limitLength:(NSInteger)length leftImage:(NSString *)leftImage middleImage:(NSString *)midImage rightImage:(NSString *)rightImage buttonClickBlock:(ButtonClickBlock)callBack returnClick:(ReturnClickBlock)returnCallBack;
//获取 textview输入的内容,有时不一定在return时获取到
@property (nonatomic,copy)NSString *result;
@end
更新。。。新增 占位文字
使用方面:只有初始化的类方法有变化
#import <UIKit/UIKit.h>
typedef void(^ButtonClickBlock)(NSInteger index);
typedef void(^ReturnClickBlock)(NSString *result);
@interface DifferInputView : UIView
/*
1.注意命名要求,@"leftImageName" 高亮则为:@"leftImageName_pre" 目的是为了少传几个参数。若传nil,则表示隐藏该按钮
2.placeString 占位文字
3.限制 字符数 为-1,则表示 没有限制
4.textview的returnType 为send
*/
+ (instancetype)InputViewWithFrame:(CGRect)frame placeHolder:(NSString *)placeString limitLength:(NSInteger)length leftImage:(NSString *)leftImage middleImage:(NSString *)midImage rightImage:(NSString *)rightImage buttonClickBlock:(ButtonClickBlock)callBack returnClick:(ReturnClickBlock)returnCallBack;
//获取 textview输入的内容,有时不一定在return时获取到
@property (nonatomic,copy)NSString *result;
@end