jeudi 29 janvier 2015

How to add custom border to multiple UITextField?

I am working on a project which have number of text fields. All text fields should have custom border at bottom and sides. enter image description here I found this answer



CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0f, self.frame.size.height - 1, self.frame.size.width, 1.0f);
bottomBorder.backgroundColor = [UIColor blueColor].CGColor;
[self.textField.layer addSublayer:bottomBorder];

CALayer *leftBorder = [CALayer layer];
leftBorder.frame = CGRectMake(0.0f, self.frame.size.height -5, 1.0f, 5.0f);
leftBorder.backgroundColor = [UIColor lightGrayColor].CGColor;
[self.textField.layer addSublayer:bottomBorder];

CALayer *rightBorder = [CALayer layer];
rightBorder.frame = CGRectMake(self.frame.size.width -1, self.frame.size.height -5, 1.0f, 5.0f);
rightBorder.backgroundColor = [UIColor lightGrayColor].CGColor;
[self.textField.layer addSublayer:rightBorder];


**But by using this method I need to add layer for each textField separately. And I have also learned that apple doesn't recommend subclassing UITextField class.


Is there any other efficient method?? **




Aucun commentaire:

Enregistrer un commentaire