在Label之后以编程方式将图像添加到TableView单元格

时间:2014-11-25 11:06:37

标签: xcode uitableview treeview

我是IOS的初学者。我有一个tableview,现在我想将一个图像放在标签右侧的单元格中。 贝娄是我的代码..

- (UITableViewCell *)treeView:(RATreeView *)treeView cellForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo
{
    //NSInteger numberOfChildren = [treeNodeInfo.children count];
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    cell.detailTextLabel.text = @"";//[NSString stringWithFormat:@"Number of children %d", numberOfChildren];
    cell.textLabel.text = ((RADataObject *)item).name;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //cell.textLabel.font = [UIFont fontWithName:@"CalvertMTStd-Bold" fonS];
    CGSize stringBoundingBox;
    CGRect frameLbl;

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        cell.textLabel.font = [UIFont fontWithName:@"CalvertMTStd-Bold" size:17];
        UIFont *customFoOnt = [UIFont fontWithName:@"CalvertMTStd-Bold" size:17]; // [UIFont ...]
        stringBoundingBox = [cell.textLabel.text sizeWithFont:customFoOnt];
        frameLbl = cell.textLabel.frame;

    }else{
        cell.textLabel.font = [UIFont fontWithName:@"CalvertMTStd-Bold" size:20];
                UIFont *customFoOnt = [UIFont fontWithName:@"CalvertMTStd-Bold" size:17]; // [UIFont ...]
        stringBoundingBox = [cell.textLabel.text sizeWithFont:customFoOnt];
        frameLbl = cell.textLabel.frame;
    }

    UIImageView *downArrow =[[UIImageView alloc] initWithFrame:CGRectMake(stringBoundingBox.width+frameLbl.origin.x, 12, 20, 20)];
    downArrow.image=[UIImage imageNamed:@"down_arrow_beg.png"];
    [cell.self addSubview:downArrow];
    //self.lbl1.font = [UIFont fontWithName:@"CalvertMTStd-Bold" size:fontSize];

    if (treeNodeInfo.treeDepthLevel == 0)
    {
        cell.detailTextLabel.textColor = [UIColor blackColor];
    }

    cell.textLabel.textColor = [UIColor whiteColor];

    return cell;
}

在上面的代码中。我没有得到确切的标签尺寸及其位置.. 我需要像

==============================
| [YOURLABEL] (IMAGE) 
-------------------------------
| [YOUR BIGGER LABEL IS HERE] (IMAGE)

0 个答案:

没有答案