Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Tablview cell - corner triangle

Has anyone seen a snippet (or class/library) that will draw that corner triangle in a tableview cell (see below image).

enter image description here

like image 238
oberbaum Avatar asked Dec 02 '11 21:12

oberbaum


1 Answers

You can create a new view from an image and then add it to the cell calling addSubview. Here is a example setting the corner upon launch:

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

        CGRect cornerFrame = CGRectMake(x, y, width, height);
        UIImageView * corner = [[UIImageView alloc] initWithFrame:cornerFrame];
        [corner setImage:[UIImage imageNamed:@"corner.jpg"]];

        [cell.contentView addSubview:corner];
    }

    return cell;
}
like image 57
Dimme Avatar answered Sep 23 '22 06:09

Dimme