【发布时间】:2010-02-26 12:50:21
【问题描述】:
我正在 iphone 应用程序中为我的自定义日历动态创建 30 个 UIButton。我还将 UILabel 添加为每个 UIButton 中的子视图。我正在为每个 UILabel 设置不同的背景颜色。
当我尝试更改 UILabel 的背景颜色时,在某些 iPhone 设备上它工作正常,但在某些 iPod touch 和 iPhone 设备上不显示任何颜色。它的行为就像我设置了 clearColor。
这是我加载一个单元格的基本代码。我将这个逻辑保持在循环中,我正在使用 UIButton 数组来创建多个单元格:
calenderCell = [UIButton buttonWithType:UIButtonTypeCustom];
calenderCell.frame = CGRectMake(xOffset, yOffset, cellWidth, cellHeight);
calenderCell.backgroundColor = [UIColor clearColor];
[calenderCell addTarget:self action:@selector(calenderCellClicked:)
forControlEvents:UIControlEventTouchUpInside];
calenderCellDate=[[UILabel alloc] initWithFrame:CGRectMake(1.0,1.0, cellWidth-1.0, cellHeight-1.0)];
calenderCellDate.text = [NSString stringWithFormat:@"%ld",dateValue];
calenderCellDate.textAlignment = UITextAlignmentCenter;
calenderCellDate.font = [UIFont fontWithName:@"Trebuchet MS" size:15.0];
calenderCellDate.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1.0];
calenderCellDate.textColor = [UIColor colorWithRed:0.44 green:0.44 blue:0.44 alpha:1.0];
[calenderCell addSubview:calenderCellDate];
[calenderCellDate release];
谁能知道这段代码有什么问题?
感谢您的帮助。
谢谢,
吉姆。
【问题讨论】: