簡體   English   中英

如何為我的表格單元創建一個附件視圖?

[英]How can I create an accessory view for my table cell like this?

基本上我需要兩個標簽。 一個帶有數字,另一個帶有下一行的常量字符串。我還需要一個語音氣泡作為附件視圖的背景。我知道如何創建一個標簽,但不知道如何將兩個標簽設置為附件視圖。 請幫忙

在此輸入圖像描述

您可以創建一個UIView並將所有必要的視圖添加為其子視圖,然后將該單個視圖作為表視圖單元的附件視圖:

UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
[container addSubview:backgroundImage];
[container addSubview:firstLabel];
[container addSubview:secondLabel];
cell.accessoryView = container;

為此,您需要創建一個ImageView或UIView並相應地設置圖像。

然后你已經設置了單元格的附件視圖,如下所示:

cell.accessoryView = <your view>;

希望,你有個主意。

干杯!

它對我來說很好.....

- (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 ..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM