Short solution for short problems

iOS: Format UITextView as UITextField

It's really simple and strange that it's not made by default.

I found a good solution that works perfect and you can see no difference between TextField and TextView, except for the height.

I made a small function that will style your TextView like a TextField:

+(void) MakeTextField:(UITextView *) vw


    vw.backgroundColor = [UIColorclearColor];

    UIImageView *borderView = [[UIImageViewalloc] initWithFrame: CGRectMake(0, 0, vw.frame.size.width, vw.frame.size.height)];

    borderView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    UIImage *textFieldImage = [[UIImageimageNamed:@"TextField.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 8, 15, 8)];

    borderView.image = textFieldImage;

    [vw addSubview: borderView];

    [vw sendSubviewToBack: borderView];


Just call this function on the DidLoad and pass the TextViews you want to format:

- (void)viewDidLoad



// Do any additional setup after loading the view.



You will also need this picture and call it TextField.png:

Thats it! Below you see 2 examples of UITextView that look like a UITextField!

Source: http://stackoverflow.com/questions/1824463/how-to-style-uitextview-to-like-rounded-rect-text-field


I was trying to manipulate some text in a richt text box. It turned out not to be as easy as I thought. One very good tip is when you are using rich text signs, enter a space between the text and the signs, or else the compiler will not understand the richt text tags.

For example, if you put /bBOLD/b0 it will display nothing, but if you put it like this: /b bold/b0 it will display it correct. To ensure following tags are correctly understood, better to put spaces before and after all tags: /b bold /b0.

Here's a little more advaced example:

StringBuilder sb = new StringBuilder();
sb.Append(@"{\rtf1\ansi Study Nr: \b " + 165 + @" \b0 \par ");
sb.Append(@"Is GLP: \b " + true.ToString() + @" \b0\par ");
sb.Append(@"Nr of CagePartners: \b " + 5 + @" \b0\par");
sb.Append(@"Minimum weight loss: \b " + 5.632 + @" \b0 g\par ");
sb.Append(@"StartDate: \b " + DateTime.Now + @" \b0\par ");
sb.Append(@"Effective animal replace period: \b " + 7 + @" \b0 days\par ");
sb.Append(@"Study supervisor: \b " + "mderaeve" + @" \b0 \par ");
richTextBox1.Rtf = sb.ToString();

So we start with {\rtf1\ansi

Then we can enter text and manipulate it.


To look for the rich text specifications, look here:

Rich Text Format (RTF) Specification, version 1.6:



WD: Rich Text Format (RTF) Specification 1.7;