Label.layer.borderColor = .... does not work (Xcode 4.3.2)

I work in a class that is a subclass of UITableViewCell and has the properties firstLabel and secondLabel declared in .h and being @synthesize in .m. When I go to programmatically program UILabels, I try to set the border around 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 he will not recognize it after entering firstLabel.layer. and press "esc" (for a list of completions). Xcode didn't come up with anything. What is the problem?

Note: if I type

 firstLabel.textAlignment = UITextAlignmentCenter; 

it works just fine and behaves as expected.

+6
source share
2 answers

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

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

+8
source

Have you set the frame width?

Like this:

 [firstLabel.layer setBorderWidth:1.0f]; 
+5
source

Source: https://habr.com/ru/post/917751/


All Articles