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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10974164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:33:27  来源:igfitidea点击:

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

iphoneiosxcodeuilabel

提问by tarheel

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.

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

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?

问题是在我输入 firstLabel.layer 后它不会识别它。并点击“esc”(以获取完成列表)Xcode 什么也没有出现。问题是什么?

Note: if I type

注意:如果我输入

firstLabel.textAlignment = UITextAlignmentCenter;

it works just fine and behaves as expected.

它工作得很好并且按预期运行。

回答by borrrden

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

您需要导入 QuartzCore 标头。 #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).

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

回答by Dzy

Did you set border width?

你设置边框宽度了吗?

Like this:

像这样:

[firstLabel.layer setBorderWidth:1.0f];