UITextView to Mimic UITextField [for the main text field in the corner]

I want to have a UITextField with multiple lines, after a quick google on this issue, I found that I should use TextView, so I switched my code to use a UITextView when I need multiple lines. My view still has another text text that I want to save.

To make my TextView look like a TextField, I had to add code to set the border and radius, but they look a bit different on iOS7. Somebody knows:

  • What is the border color of a UITextField? when both are on and off, so I can send a text image to match it.
  • What is the radius of the angle of the TextField.
  • What is the background color for a UITextField when it is disabled [attached image shows that the text field has a lighter shade of gray when it is disabled]? so I can set my text view to the same color when I turn off user interaction.

If you need to continue to use the text box for multi-line text, I’m all ears and I switch to using it.

Regards,

enter image description here

+4
source share
4 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;

Small differences in the parameters make it more like a UITextField (hopefully).

+7
source

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 result.

+3
source

UITextView, iOS 7 , UITextField

:

@interface MyTextView : UITextView
@end

"editable":

@implementation MyTextView

//================================================================================

- (id) initWithFrame: (CGRect) frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self commonInit];
    }
    return self;
}

//================================================================================

- (id) initWithCoder: (NSCoder *) aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self)
    {
        [self commonInit];
    }
    return self;
}

//================================================================================

- (void) commonInit
{
    self.layer.borderWidth  = 1.0f;
    self.layer.borderColor  = [[UIColor colorWithRed:232.0/255.0
                       green:232.0/255.0 blue:232.0/255.0 alpha:1] CGColor];
    self.layer.cornerRadius = 6;
}

//================================================================================

- (void) setEditable: (BOOL) editable
{
    [super setEditable:editable];

    if (editable)
    {
        self.backgroundColor = [UIColor whiteColor];
    }
    else
    {
        self.backgroundColor = [UIColor colorWithRed:250.0/255.0
                                green:250.0/255.0 blue:250.0/255.0 alpha:1];
    }
}

//================================================================================

@end
0
source

This is the closest I got with a enabled UITextView

[yourTextView.layer setBorderColor:[[[UIColor lightGrayColor] colorWithAlphaComponent:0.2] CGColor]];
[yourTextView.layer setBorderWidth:2.0];
yourTextView.layer.cornerRadius = 5;
yourTextView.clipsToBounds = YES;
yourTextView.textColor = [UIColor lightGrayColor];
0
source

All Articles