Dotted / Dotted Border for UITextView / UITextField

I want to set a dotted / dotted border for my UITextFieldand UITextView.

How can i do this? I know that I can set the border with this line of code:

[self.textFieldCardTitle.layer setBorderWidth:1.0];
[self.textFieldCardTitle.layer setBorderColor:[[UIColor whiteColor] CGColor]];  

Note. I already have an idea to add UIImageViewfor UITextViewand install there image with a dotted frame. But I do not want to decide that.

+5
source share
3 answers

You can try, for example, the following approach:

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

2) Add an image to the project.

3) Set the border (as in the code of your question) and set the color with the picture:

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

(, , , ), : , , . .

+8

Dotted/Dashed Border UIView UITextField : -

CAShapeLayer * _border = [CAShapeLayer layer];
_border.strokeColor = [UIColor redColor].CGColor;
_border.fillColor = nil;
_border.lineDashPattern = @[@4, @2];
[YOURVIEW.layer addSublayer:_border];

//for a square effect
_border.path = [UIBezierPath bezierPathWithRect:YOURVIEW.bounds].CGPath;
//for a rounded effect
//_border.path = [UIBezierPath bezierPathWithRoundedRect:YOURVIEW.bounds cornerRadius:txtUserName.frame.size.height / 2].CGPath;

_border.frame = YOURVIEW.bounds;

. .

, , . .:)

+4

Swift:

self.textFieldCardTitle.layer.borderWidth = 3
self.textFieldCardTitle.layer.borderColor = (UIColor(patternImage: UIImage(named: "dot")!)).CGColor

, . StackOverflow , , , , , URL- .

dotdot @ 2xdot @ 3x

+3
source

All Articles