views:

4356

answers:

9

Hello all,

I am using a text view as a comment composer .

In the properties inspector I can't find anything like border style property so that I can make it to rounded rect something like uitextfield.

so the question is : How to style uitextview like uitextfield rounded rect ?

+1  A: 

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.

Morion
+15  A: 

There is no implicit style that you have to choose, it involves writing a bit of code using the QuartzCore framework:

//first, you
#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)];

//The rounded corner part, where you specify your view's corner radius:
textView.layer.cornerRadius = 5;
textView.clipsToBounds = YES;

It only works on OS 3.0 and above, but I guess now it's the de facto platform anyway.

luvieere
thanks it is just amazing ...
hib
Thanks its working fine..
Warrior
+2  A: 

Very nice! Now if you could include the shadow effect similar to UITextField without having to use a custom image, that would be awesome! :)

DSpeckleback
If you want to ask a follow-up question about the shadow you should better post it as a new question (The "Ask Question" button in the top right of the page). More people would see it that way and would try to answer.
sth
+1  A: 

I don't have enough points to leave a comment to luvieere's answer so here goes: It works great but you have to remember to import <QuartzCore/QuartzCore.h> or else the code won't compile.

iphone007
he has written the thing in the code see the code
hib
Yes, I did see it but I was curious to see whether including QuartzCore was necessary. It was. Somehow, that import extends the existing classes.
iphone007
A: 

just set the style to bordered...

txtfield.borderStyle=UITextBorderStyleRoundedRect;

Hope this is helpful..

Thanx, Varma

Suriya
borderStyle can't be set for a UITextView. You are referring to a UITextField which is different.
Sheehan Alam
i have responded above for correct answer
Suriya
there is no cornerRadius for txtView.layer
David
@David: sorry again but you have to import <QuartzCore/QuartzCore.h>for using cornerRadius. Thanks
Suriya
Yep, figure that out, thanks.
David
+1  A: 

For the best effect you have to use a custom (stretchable) background image. This is also how the UITextField's rounded border is drawn.

KennyTM
A: 

ohh yes.. sorry for the misunderstanding... i have answered for uitextfield instead of ui textview.. sorry again..

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;

Edit: you have to import

                       QuartzCore/QuartzCore.h

for using corner radius

Suriya
A: 

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. http://www.mercuryintermedia.com/blog/index.php/2009/03/iphone-ui-vector-elements

MattDiPasquale
+2  A: 

this code worked well for me:

    [yourTextView.layer setBackgroundColor: [[UIColor whiteColor] CGColor]];
    [yourTextView.layer setBorderColor: [[UIColor grayColor] CGColor]];
    [yourTextView.layer setBorderWidth: 1.0];
    [yourTextView.layer setCornerRadius:8.0f];
    [yourTextView.layer setMasksToBounds:YES];
hanumanDev