Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView to Mimic UITextField [for basic round corner text field]

I want to have UITextField with multiple lines, after a quick google on this issue I found that I should use TextView so I did switch my code to use UITextView when I want multiple lines. My View still have other one line textField that I want to keep.

To make my TextView looks like TextField, I had to add code to set border and radius, but they look a little bit different on iOS7. Does anyone know:

  • what is the color for the UITextField border? when both enabled and disabled so I can sent my textview to match it.
  • what is radius of the corner of TextField.
  • what is the background color for UITextField when it is disabled[attached picture shows the text field has lighter shade of grey when it is disabled]? so i can set my text view to the same color when i disable user interaction.

If there is away to keep using textfield for multiline text, I am all ears and i switch to use it.

Best Regards,

enter image description here

like image 936
user2708681 Avatar asked Dec 26 '13 20:12

user2708681


2 Answers

I use this:

textView.layer.borderColor = [[UIColor colorWithRed:215.0 / 255.0 green:215.0 / 255.0 blue:215.0 / 255.0 alpha:1] CGColor];
textView.layer.borderWidth = 0.6f;
textView.layer.cornerRadius = 6.0f;

little differences in the params make it looks more like UITextField(I hope).

like image 155
Hampotato Avatar answered Oct 14 '22 04:10

Hampotato


I use this:

#import <QuartzCore/QuartzCore.h>

-(void) textViewLikeTextField:(UITextView*)textView
{
    [textView.layer setBorderColor:[[UIColor colorWithRed:212.0/255.0
                                                                       green:212.0/255.0
                                                                        blue:212.0/255.0
                                                                       alpha:1] CGColor]];
    [textView.layer setBorderWidth:1.0f];
    [textView.layer setCornerRadius:7.0f];
    [textView.layer setMasksToBounds:YES];
}

and get a good resut.

like image 44
Javi Campaña Avatar answered Oct 14 '22 05:10

Javi Campaña