Objective c UILabel中的图形边框

Objective c UILabel中的图形边框,objective-c,ios,Objective C,Ios,嗯,我对UILabel中的边框绘制有一些问题。这是我的代码片段 CGRect frame = CGRectMake(10, 10, 320, 120); UILabel *label = [[UILabel alloc] initWithFrame:frame]; label.textColor = [UIColor greenColor]; label.font = [UIFont fontWithName:@"Verdana" size:12]; label.textAlignment =

嗯,我对UILabel中的边框绘制有一些问题。这是我的代码片段

CGRect frame = CGRectMake(10, 10, 320, 120);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.textColor = [UIColor greenColor];
label.font = [UIFont fontWithName:@"Verdana" size:12];
label.textAlignment = UITextAlignmentCenter;
label.text = @"Some text to display"; 
label.layer.backgroundColor = [UIColor cyanColor].CGColor;
label.layer.borderColor = [UIColor redColor].CGColor;
[self.window addSubview:label];
[label release];label=nil;
我包括QuartzCore,当我在sumulator中启动应用程序时,我使用iOS4.3显示文本,但不显示边框和背景色。
这里怎么了?

查看CALayer.h,我们看到
borderWidth
的默认值是0.0

/* The width of the layer's border, inset from the layer bounds. The
 * border is composited above the layer's content and sublayers and
 * includes the effects of the `cornerRadius' property. Defaults to
 * zero. Animatable. */

@property CGFloat borderWidth;
要显示边框,必须将
边框宽度设置为大于零的值

您可以直接在标签上设置背景色,如下所示:

label.backgroundColor = [UIColor cyanColor];
要设置边框,需要设置宽度,如下所示:

label.layer.borderWidth = 2.0f;
设置边框宽度后,要设置标签上边框的颜色,您需要设置视图的图层边框,它使用CGColor,因此必须执行以下操作:

label.layer.borderColor = [UIColor redColor].CGColor;
如果您想要圆角,可以添加以下内容:

label.layer.cornerRadius = 10.0f;

您不需要设置背景色。您只需设置borderWidth和borderColor。

很有趣。我正在做一件我不希望出现边界的事情。我在标签周围发现了一个模糊的边框。我的布局如下:两个UILabel以白色背景放置在UIView中。此UIView本身是具有红色背景的较大UIView的子视图。模糊的轮廓呈灰色。
label.layer.borderColor = [UIColor darkGrayColor].CGColor;
label.layer.borderWidth = 1.0;