您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页UITextView设置键盘隐藏和圆角

UITextView设置键盘隐藏和圆角

来源:伴沃教育

第一步先用xib画出来页面,并且拖出来关系

第二步在.m文件中写方法

注:此处用于直接粘贴,与图片代码相同

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view from its nib.

self.contentTV.delegate = self;

//字体大小

self.contentTV.font= [UIFont systemFontOfSize:16];

//添加滚动区域

// self.contentTV.contentInset= UIEdgeInsetsMake(-11, -6, 0, 0);

//是否可以滚动

self.contentTV.scrollEnabled = NO;

//获得第一响应者身份

[self.contentTV becomeFirstResponder];

//返回键的类型

self.contentTV.returnKeyType = UIReturnKeyDefault;

//键盘类型

self.contentTV.keyboardType = UIKeyboardTypeDefault;

UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];

//设置style

[topView setBarStyle:UIBarStyleDefault];

//设置圆角

[self.contentTV.layer setCornerRadius:5];

//定义两个flexibleSpace的button,放在toolBar上,这样完成按钮就会在最右边

UIBarButtonItem * button1 =[[UIBarButtonItem  alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace

target:self action:nil];

UIBarButtonItem * button2 = [[UIBarButtonItem  alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace

target:self action:nil];

//定义完成按钮

UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成"style:UIBarButtonItemStyleDone

target:self action:@selector(resignKeyboard)];

//在toolBar上加按钮

NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];

[topView setItems:buttonsArray];

[self.contentTV setInputAccessoryView:topView];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

-

(void)resignKeyboard

{

[self.contentTV resignFirstResponder];

}

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务