Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

label.layer.borderColor = .... not working (Xcode 4.3.2)

I am working in a class that is a subclass of UITableViewCell and have firstLabel and secondLabel properties declared in .h and being @synthesize in .m. When I go to format the UILabels programmatically, I try to set the border around the firstLabel. From the answer given in this question, I tried to do the same in my project.

firstLabel.layer.borderColor = [UIColor blackColor].CGColor;

The problem is that it won't recognize it, after I type firstLabel.layer. and hit 'esc' (to get the list of completions) Xcode comes up with nothing. What is the problem?

Note: if I type

firstLabel.textAlignment = UITextAlignmentCenter;

it works just fine and behaves as expected.

like image 685
tarheel Avatar asked Jun 11 '12 03:06

tarheel


2 Answers

You need to import the QuartzCore header. #import <QuartzCore/QuartzCore.h>

(And don't forget to add the QuartzCore library as well or you will get a linker error when you try to build).

like image 146
borrrden Avatar answered Oct 28 '22 05:10

borrrden


Did you set border width?

Like this:

[firstLabel.layer setBorderWidth:1.0f];
like image 40
Dzy Avatar answered Oct 28 '22 04:10

Dzy