Just like UITextField, but there are some differences listed below.
Last active
August 29, 2015 14:02
-
-
Save JeOam/52bfa9d6ecbc00c81bb1 to your computer and use it in GitHub Desktop.
UITextView 模板
Style UITextview to like Rounded Rect text field:
There is no implicit style that you have to choose, it involves writing a bit of code using the QuartzCore framework:
//first, you may need...
#import <QuartzCore/QuartzCore.h>
//Here I add a UITextView in code, it will work if it's added in IB too
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(50, 220, 200, 100)];
//To make the border look very close to a UITextField
[textView.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.3] CGColor]];
[textView.layer setBorderWidth:2.0];
//The rounded corner part, where you specify your view's corner radius:
textView.layer.cornerRadius = 5;
textView.clipsToBounds = YES;
via clock
UITextView dissmissKeyBoard:
// 在输入框加一个 Done 按钮退出键盘
UIToolbar *topView = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
// 这里缺少 Button1,Button2 的话,doneButton 按钮会被放到 toolbar 的左边
UIBarButtonItem *Button1 = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStyleBordered target:self action:nil];
UIBarButtonItem *Button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(dismissKeyBoard)];
[topView setItems:@[Button1,Button2,doneButton]];
[self.textView setInputAccessoryView:topView];
-(void)dismissKeyBoard{
[self.textView resignFirstResponder];
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Placeholder in UITextView:
Easy way, just create placeholder text in
UITextView
by using the followingUITextViewDelegate
methods:just remember to set myUITextView with the exact text on creation e.g.
and make the parent class a
UITextViewDelegate
before including these methods e.g.via: click