基本上我需要两个标签。一个带有数字,另一个带有下一行的常量字符串。我还需要一个语音气泡作为附件视图的背景。我知道如何创建一个标签,但不知道如何将两个标签设置为附件视图。请帮忙
答案 0 :(得分:7)
您可以创建一个UIView并将所有必要的视图添加为其子视图,然后将该单个视图作为表视图单元的附件视图:
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
[container addSubview:backgroundImage];
[container addSubview:firstLabel];
[container addSubview:secondLabel];
cell.accessoryView = container;
答案 1 :(得分:3)
为此,您需要创建一个ImageView或UIView并相应地设置图像。
然后你设置了单元格的附件视图,如下所示:
cell.accessoryView = <your view>;
希望,你有个主意。
干杯!
答案 2 :(得分:0)
它适用于我......
- (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.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(25, 25, 100, 21)];
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(25,42, 100, 21)];
label1.backgroundColor = [UIColor clearColor];
label2.backgroundColor = [UIColor clearColor];
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 110)];
[container setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Bukkl.png"]]];
[container addSubview:label1];
[container addSubview:label2];
label1.text = @"HIIIIIIII";
label2.text = @"@@@BBBBBB";
cell.accessoryView = container;
}
return cell;
}
如果它运作良好,不要忘记upvote ..