Objective-C-如何自定义键盘(iOS)
2016-09-21 13:25
218 查看
//createMyInputView该方法返回一个UIImageView类型的视图
UIImageView *myView= [self
createMyInputView];
//让此视图作为键盘的背景视图
textField.inputView = myView;
//添加附件区域
UIView *upView=[[UIView
alloc]initWithFrame:CGRectMake(0,
0, self.view.frame.size.width,
60)];
//附件区域的颜色
upView.backgroundColor=[UIColor
grayColor];
//让upView作为附件区域
textField.inputAccessoryView = upView;
//在附件区域中添加“确定”按钮
UIButton *sendButton=[UIButton
buttonWithType:UIButtonTypeSystem];
sendButton.frame=CGRectMake(self.view.frame.size.width-80,
6, 80,
40);
[sendButton setTitle:@"确定"
forState:UIControlStateNormal];
[upView addSubview:sendButton];
//自定义键盘
-(UIImageView *)createMyInputView{
//创建一个背景ImageView
UIImageView *inputView=[[UIImageView
alloc]initWithFrame:CGRectMake(0,
0, self.view.frame.size.width,
200)];
//添加背景图片
inputView.image = [UIImage
imageNamed:@"DOVE 1"];
//打开用户交互
inputView.userInteractionEnabled =
YES;
//视图的背景色
inputView.backgroundColor=[UIColor
colorWithRed:1
green:1
blue:1
alpha:0.5];
//添加按钮
NSArray *titleArray=@[@"京",@"津",@"追",@"梦",@"人",@"自",@"定",@"义",@"键",@"盘",@"一",@"二",@"三",@"四",@"五",@"六",@"七",@"八",@"九",@"十",@"取钱",@"红包",@"收"];
//有多少个字就创建多少个按钮
for(int i =
0; i< titleArray.count; i++)
{
//创建按钮
UIButton *button=[UIButton
buttonWithType:UIButtonTypeSystem];
//按钮的坐标
button.frame=CGRectMake(40*(i%10),
i/10*40,
40, 40);
//按钮上显示的文字
[button setTitle:titleArray[i]
forState:UIControlStateNormal];
//把创建的每一个按钮添加到inputView上
[inputView addSubview:button];
//设置按钮的tag值
button.tag = i+1;
//给每个按钮添加点击事件
[button addTarget:self
action:@selector(btnClick:)
forControlEvents:UIControlEventTouchUpInside];
}
//返回背景视图
return inputView;
}
//按钮的点击事件
-(void)btnClick:(UIButton *)button
{
//在此处做响应的处理
}
UIImageView *myView= [self
createMyInputView];
//让此视图作为键盘的背景视图
textField.inputView = myView;
//添加附件区域
UIView *upView=[[UIView
alloc]initWithFrame:CGRectMake(0,
0, self.view.frame.size.width,
60)];
//附件区域的颜色
upView.backgroundColor=[UIColor
grayColor];
//让upView作为附件区域
textField.inputAccessoryView = upView;
//在附件区域中添加“确定”按钮
UIButton *sendButton=[UIButton
buttonWithType:UIButtonTypeSystem];
sendButton.frame=CGRectMake(self.view.frame.size.width-80,
6, 80,
40);
[sendButton setTitle:@"确定"
forState:UIControlStateNormal];
[upView addSubview:sendButton];
//自定义键盘
-(UIImageView *)createMyInputView{
//创建一个背景ImageView
UIImageView *inputView=[[UIImageView
alloc]initWithFrame:CGRectMake(0,
0, self.view.frame.size.width,
200)];
//添加背景图片
inputView.image = [UIImage
imageNamed:@"DOVE 1"];
//打开用户交互
inputView.userInteractionEnabled =
YES;
//视图的背景色
inputView.backgroundColor=[UIColor
colorWithRed:1
green:1
blue:1
alpha:0.5];
//添加按钮
NSArray *titleArray=@[@"京",@"津",@"追",@"梦",@"人",@"自",@"定",@"义",@"键",@"盘",@"一",@"二",@"三",@"四",@"五",@"六",@"七",@"八",@"九",@"十",@"取钱",@"红包",@"收"];
//有多少个字就创建多少个按钮
for(int i =
0; i< titleArray.count; i++)
{
//创建按钮
UIButton *button=[UIButton
buttonWithType:UIButtonTypeSystem];
//按钮的坐标
button.frame=CGRectMake(40*(i%10),
i/10*40,
40, 40);
//按钮上显示的文字
[button setTitle:titleArray[i]
forState:UIControlStateNormal];
//把创建的每一个按钮添加到inputView上
[inputView addSubview:button];
//设置按钮的tag值
button.tag = i+1;
//给每个按钮添加点击事件
[button addTarget:self
action:@selector(btnClick:)
forControlEvents:UIControlEventTouchUpInside];
}
//返回背景视图
return inputView;
}
//按钮的点击事件
-(void)btnClick:(UIButton *)button
{
//在此处做响应的处理
}
相关文章推荐
- Objective-C-如何监测键盘的高度(iOS)
- Swift-如何自定义键盘(iOS)
- ios中如何自定义数字键盘
- [Xamarin.iOS] 如何引用Objective-c寫的Class Library (转帖)
- IOS开发之自定义系统弹出键盘上方的view(转载)
- 如何在Photoshop中自定义键盘快捷键
- IOS开发之自定义系统弹出键盘上方的view
- IOS开发 当键盘出现的时候,如何让UITextField自动上移
- iOS 自定义键盘
- ios键盘通知和自定义键盘
- Objective-C,ios,属性声明(property declarations), 自定义属性,自动生成 get 和 set 方法,getter 和 setter
- iOS中如何添加自定义的字体
- 如何保持iOS上键盘出现时输入框不被覆盖
- Hack the UIKeyboard(自定义iOS内置的键盘)
- [iOS]如何在键盘上添加一层遮罩层
- iOS开发之如何自定义UIActionSheet(UIAlertView)中的内容
- iOS开发笔记--如何自定义启动画面Default.png加载时间
- 为数字键盘添加自定义按钮的方法(iOS所有版本适用
- IOS自定义的数字键盘 FPNumberPadView
- [置顶] Objective-C ,ios,iphone开发基础:在UITextField输入完以后,隐藏键盘,