您的位置:首页 > 产品设计 > UI/UE

UITextView的内容长度限制

2015-07-06 10:40 627 查看
(void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

self.textView=[[UITextView alloc]initWithFrame:self.view.frame];

self.textView.text=@”请输入文字”;

[self.view addSubview:self.textView];

}

(void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

(void)viewWillAppear:(BOOL)animated

{

//注册通知,监听键盘出现

[[NSNotificationCenter defaultCenter]addObserver:self

selector:@selector(handleKeyboardDidShow:)

name:UIKeyboardDidShowNotification

object:nil];

//注册通知,监听键盘消失事件

[[NSNotificationCenter defaultCenter]addObserver:self

selector:@selector(handleKeyboardDidHidden)

name:UIKeyboardDidHideNotification

object:nil];

[super viewWillAppear:YES];

}

//监听事件

- (void)handleKeyboardDidShow:(NSNotification*)paramNotification

{

//获取键盘高度

NSValue *keyboardRectAsObject=[[paramNotification userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey];

CGRect keyboardRect;
[keyboardRectAsObject getValue:&keyboardRect];

self.textView.contentInset=UIEdgeInsetsMake(0, 0,keyboardRect.size.height, 0);


}

(void)handleKeyboardDidHidden

{

self.textView.contentInset=UIEdgeInsetsZero;

}

(void)viewDidDisappear:(BOOL)animated

{

[[NSNotificationCenter defaultCenter] removeObserver:self];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: