ios - UILabel 的边框很模糊

标签 ios uilabel border calayer

我认为默认边框宽度为 0.0。所以我很惊讶我在 UILabels 周围看到了边框。我什至尝试使用 CALayer 将边框设置为 0.0 并将其设置为白色,但我仍然看到模糊的轮廓。这是我的代码。

-(UIView *)calendarDay:(int)d date:(NSDate *)date width:(float)w height:(float)h
{
//d is the day number in the month of the 28/293 calendar. It should display in bold in the upper, left.
//date is the date of that day. It should display in the upper, right.
//w is the width of the UIView in which to insert the labels.
//h is the height of the UIView in which to insert the labels.
//First create an outer view with a red background color.
UIView *frameView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, h)];
[frameView setBackgroundColor:[UIColor redColor]];
//Next decrease the width and height slightly to make a smaller view that fits inside the larger one.
w = w*0.98;
h = h*0.98;
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM-dd "];
UILabel *dayNumber = [[UILabel alloc] init];
dayNumber.text = [NSString stringWithFormat:@"%2d",d];
dayNumber.font = [UIFont boldSystemFontOfSize:16];
dayNumber.frame = CGRectMake(0,0,w/2,h/5);
dayNumber.backgroundColor = [UIColor whiteColor];
UILabel *gregDate = [[UILabel alloc] init];
gregDate.text = [dateFormat stringFromDate:date];
gregDate.textAlignment = NSTextAlignmentRight;
gregDate.frame = CGRectMake(w/2,0,w/2,h/5);
gregDate.backgroundColor = [UIColor whiteColor];

以下三行试图使边框消失。这没有什么区别。

CALayer *gregDateLayer = [gregDate layer];
[gregDateLayer setBorderColor:[[UIColor whiteColor] CGColor]];
[gregDateLayer setBorderWidth:0.0];

[gregDate setTextColor:[UIColor blackColor]];
CGRect dayRect = CGRectMake(0, 0, w, h);
UIView *dayToReturn = [[UIView alloc] initWithFrame:dayRect];
[dayToReturn setBackgroundColor:[UIColor whiteColor]];
dayNumber.center = CGPointMake(w/4 ,h/4);
gregDate.center = CGPointMake(w*3/4,h/4);
[dayToReturn addSubview:dayNumber];
[dayToReturn addSubview:gregDate];
[frameView addSubview:dayToReturn];
dayToReturn.center = frameView.center;
return frameView;
}

最佳答案

我认为你所认为的边框实际上是 UILabel 的背景颜色。

将 UILabels 的背景颜色设置为 [UIColor clearColor]

关于ios - UILabel 的边框很模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14150422/

相关文章:

ios - 同时替换 NSString 中的多个字符

ios - 未找到自动链接框架

ios - 为什么 UIFont sizeWithFont 在其计算中包含空格?

ios - 连续为单个标签着色

opengl-es - 如何使用 GLSL 在纹理周围绘制边框

ios - 如何以编程方式添加多个导航 Controller ?

ios - 所选行应用程序是否崩溃

ios - 根据 UIPicker 位置动态调整 UILabel x 值?

R中的绘图周围的圆形边框

html - 如何定义字段集边框颜色?