I am using a text view as a comment composer.
In the properties inspector I can\'t find anything like a border style property so that I can make use a rounded rect,
You may want to check out my library called DCKit.
You'd be able to make a rounded corner text view (as well as text field/button/plain UIView
) from the Interface Builder
directly:
It also has many other useful features, such as text fields with validation, controls with borders, dashed borders, circle and hairline views etc.
#import <QuartzCore/QuartzCore.h>
- (void)viewDidLoad{
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(50, 220, 200, 100)];
textView.layer.cornerRadius = 5;
textView.clipsToBounds = YES;
[textView.layer setBackgroundColor: [[UIColor whiteColor] CGColor]];
[textView.layer setBorderColor: [[UIColor grayColor] CGColor]];
[textView.layer setBorderWidth: 1.0];
[textView.layer setCornerRadius:8.0f];
[textView.layer setMasksToBounds:YES];
[self.view addSubView:textview];
}
I don't think that it is possible. but you can do UITableView
(grouped) with 1 section and 1 empty cell and use it as a container for your UITextView
.
There is a great background image that is identical to the UITextView
used for sending text messages in iPhone's Messages app. You'll need Adobe Illustrator to get & modify it.
iphone ui vector elements
Edit: You have to import
#import <QuartzCore/QuartzCore.h>
for using corner radius.
Try this it will work for sure
UITextView* txtView = [[UITextView alloc] initWithFrame:CGRectMake(50, 50, 300, 100)];
txtView.layer.cornerRadius = 5.0;
txtView.clipsToBounds = YES;
As
Rob figured it out setting the if you want the border color to be similar as UITextField
then you need to change the border width to 2.0 and color to gray by adding the following line
[textView.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
[textView.layer setBorderWidth:2.0];
Here is my solution:
- (void)viewDidLoad {
[super viewDidLoad];
self.textView.text = self.messagePlaceholderText;
self.textView.layer.backgroundColor = [[UIColor whiteColor] CGColor];
self.textView.layer.borderColor = [[[UIColor grayColor] colorWithAlphaComponent:0.3] CGColor];
self.textView.layer.borderWidth = 0.5;
self.textView.layer.cornerRadius = 5.5f;
self.textView.layer.masksToBounds = YES;
self.textView.textColor = [[UIColor grayColor] colorWithAlphaComponent:0.4];
}
- (void)textViewDidBeginEditing:(UITextView *)textView {
if (textView == self.tvMessage) {
// Delete placeholder text
if ([self.textView.text isEqualToString:self.messagePlaceholderText]) {
self.textView.text = @"";
self.textView.textColor = [UIColor blackColor];
}
}
}
- (void)textViewDidEndEditing:(UITextView *)textView {
if (textView == self.tvMessage) {
// Write placeholder text
if (self.textView.text.length == 0) {
self.textView.text = self.messagePlaceholderText;
self.textView.textColor = [[UIColor grayColor] colorWithAlphaComponent:0.4];
}
}
}