label.layer.borderColor = ....不工作(Xcode 4.3.2)

tar*_*eel 6 iphone xcode uilabel ios

我在一个类中工作,该类是UITableViewCell的子类,并且在.h中声明了firstLabel和secondLabel属性,并且在.m中是@synthesize.当我以编程方式格式化UILabels时,我尝试在firstLabel周围设置边框.从这个问题的答案中,我试图在我的项目中做同样的事情.

firstLabel.layer.borderColor = [UIColor blackColor].CGColor;
Run Code Online (Sandbox Code Playgroud)

我键入firstLabel.layer后,问题是它无法识别它.并点击'esc'(获得完成列表)Xcode没有任何结果.问题是什么?

注意:如果我输入

firstLabel.textAlignment = UITextAlignmentCenter;
Run Code Online (Sandbox Code Playgroud)

它工作正常,行为符合预期.

bor*_*den 8

您需要导入QuartzCore标头. #import <QuartzCore/QuartzCore.h>

(并且不要忘记添加QuartzCore库,否则在尝试构建时会出现链接器错误).


小智 5

你设置边框宽度了吗?

像这样:

[firstLabel.layer setBorderWidth:1.0f];
Run Code Online (Sandbox Code Playgroud)