Question

Basically I need two labels. one with a number and other with the constant string letters on next line.Also I need a speech bubble as background for accessory view.I know how to create one label , but no idea about setting two label as accessory view. Please help

enter image description here

Was it helpful?

Solution

You can create a UIView and add all the necessary views to it as its subviews, then make that single view the accessory view of the table view cell:

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

OTHER TIPS

For that, you need to create one ImageView or UIView and set the image accordingly.

Then you have set the accessory view of the cell like below:

cell.accessoryView = <your view>;

Hope, you got an idea.

Cheers!

Its works fine for me.....

- (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;
}

If it works well than don't forget to upvote..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top