为 iPhone 应用程序的 UILabel 设置零背景



我有一个UILabel,这是我写的代码:

UILabel *tl = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 50, 30)];
tl.font = [UIFont systemFontOfSize:12];
tl.backgroundColor = nil;
// tl.text = @"123"; // 1
tl.text = @"你好"; // 2
tl.textColor = [UIColor blackColor];
[self.view addSubview:tl];

就像注释 1,如果用英文或数字设置,整个 UILabel 就会变得秃的,但如果是中文设置的,那就是正常颜色。

@fengshaobo在

背景色中使用[UIColor clearColor];

你的答案是[UIColor clearColor] .不要使用nil

tl.backgroundColor = [UIColor clearColor];

最新更新