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

时间:2012-06-11 03:12:21

标签: iphone ios xcode uilabel

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

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

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

注意:如果我输入

firstLabel.textAlignment = UITextAlignmentCenter;

它工作得很好并且表现得像预期的那样。

2 个答案:

答案 0 :(得分:8)

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

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

答案 1 :(得分:5)

你设置了边框宽度吗?

像这样:

[firstLabel.layer setBorderWidth:1.0f];
相关问题