Dotted / Dashed border for UITextView / UITextField

border, ios, objective-c, uitextfield, uitextview

Solution

You could try, for example, next approach:

1) Create image that will represent your border (for example: one dot and space)

2) Add image to project.

3) Set border (as in code in your question) and set color with pattern:

[self.textFieldCardTitle.layer setBorderWidth:6.0];
[self.textFieldCardTitle.layer setBorderColor:[[UIColor colorWithPatternImage:[UIImage imageNamed:@"dashed_white.png"]] CGColor]];

As border is drawn along 4 sides (left, right, bottom, top) you should use square image: for example, pixel in middle is black and pixels around it are transparent. So copies of that image will be placed around the view.

Problem

I want to set a Dotted / Dashed border for my `UITextField` and `UITextView`. How can I do that? I know that, I can set border with this line of code: ``` [self.textFieldCardTitle.layer setBorderWidth:1.0]; [self.textFieldCardTitle.layer setBorderColor:[[UIColor whiteColor] CGColor]]; ``` Notice: I already have the idea to add a `UIImageView` behind the `UITextView` and set there an image with dashed border. But I don't want to solve it that way.

Original source

Related problems