为 iphone 应用程序的 UILabel 设置透明背景 [英] setting transparent background for UILabel for iphone application
本文介绍了为 iphone 应用程序的 UILabel 设置透明背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 UITableView 中有一个 UILabel.这是我在 cellForRowAtIndexPath 中编写的代码
I have a UILabel in UITableView. Here is the code i have written in cellForRowAtIndexPath
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(30.0, 5.0, 250.0, 35.0) reuseIdentifier:CellIdentifier] autorelease];
}
CGRect rect = CGRectMake(30.0, 5.0, 250.0, 35.0);
UILabel *label = [[UILabel alloc] initWithFrame:rect];
label.opaque = NO;
label.font = [UIFont systemFontOfSize:14];
label.numberOfLines = 2;
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor darkGrayColor];
label.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
[label setText:@"Test Message"];
[cell addSubview:label];
[label release];
cell.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
我的目的是将单元格和 UILabel 的背景设置为透明.
My intention was to set the background of cell and UILabel as transparent.
但是它不起作用.谁能告诉我我在这里缺少什么
But it is not working. can any one tell me what i am missing here
谢谢
桑迪普
推荐答案
更改以下行:
label.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
为此:
label.backgroundColor = [UIColor clearColor];
这篇关于为 iphone 应用程序的 UILabel 设置透明背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文