Well, I have some problems with border drawing in UILabel. Here is my snippet of code
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;
I have QuartzCore included and I use iOS4.3 When I launch the app in sumulator text is displayed but not the border and background color.
What is wrong here ?
Looking in CALayer.h, we see that the default value for
borderWidthis 0.0.In order for the border to appear, you must set the
borderWidthto something greater than zero.You can set the background color on the label directly as so:
To set a border, you need to set the width, which can be done like so:
Once you have set a border width, to set the color of the border on the label, you’re setting the view’s layer’s border, which uses a CGColor, so you’ll have to do this:
And if you want to round the corners, you can add this:
You don’t need to set the background color. You really need to only set the borderWidth and borderColor.