我将标签添加到uiimage,然后将该图像添加到可用视图中。但它没有显示。任何人都可以帮忙吗?将uilabel添加到显示在适合视图上的uiimage上
这是代码我使用:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
//image which contains label
UIImageView *BgImage=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell-bg.png"]];
BgImage.frame=cell.frame;
//label which will be on image
UILabel *NameLAbel=[[UILabel alloc]initWithFrame:CGRectMake(25, 5, 45, 45)];
NameLAbel.textColor=[UIColor blackColor];
if (indexPath.row==0) {
[email protected]"Home";
}
else if (indexPath.row==1) {
[email protected]"You";
}
else if (indexPath.row==2) {
[email protected]"Contacts";
}
else if (indexPath.row==3) {
[email protected]"Settings";
}
else {
[email protected]"Sign Out";
}
NSLog(@"%@",NameLAbel.text);
[BgImage addSubview:NameLAbel];
//adding image on cell
[cell.contentView addSubview:BgImage];
[NameLAbel release];
[BgImage release];
return cell;
}
只是标签没有显示吗?或没有显示? – 2012-03-12 14:51:24