0

私は Storyboard を使用しており、UITableView にデータを表示しています。UITableView での画像の表示に問題があります。画像の動的フレームを表示したいのですが、うまくいきません。

最初:私は文字列を持っています

NSString * abc = @"Helllo stackoverflow, Im a new bie, Im glad with you.";

2番目:NSString「abc」の幅、高さを取得しています

CGSize sizeLabel = [(text ? text : @"") sizeWithFont:[UIFont systemFontOfSize:13]constrainedToSize:CGSizeMake(180, 9999) lineBreakMode:NSLineBreakByWordWrapping];

最後に: sizeLabel.width, sizeLabel.height をフレーム画像に設定しています

int x = 60;
int y = 30;
image.frame = CGRectMake(x,y,sizeLabel.width,sizeLabel.height);

フレームUILabelを設定すると->実行OK

comCell.lblText.frame = CGRectMake(x,y,sizeLabel.width,sizeLabel.height);

ここに私の完全なコード:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSDictionary *dataTable = [_itemsNames objectAtIndex:indexPath.row];
    NSString *text = [dataTable objectForKey:@"Content"];

    NSString *cell = @"cellCus";
    CustomCell *comCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cell];

    UIFont *font=[UIFont systemFontOfSize:13];
    CGSize sizeLabel = [(abc ? abc : @"") sizeWithFont:font constrainedToSize:CGSizeMake(180, 9999) lineBreakMode:NSLineBreakByWordWrapping];

    UIImage *img = [UIImage imageNamed:@"trang.png"];

    //Image
    comCell.imgAvatar.image = [img stretchableImageWithLeftCapWidth:15 topCapHeight:14];
    [comCell.imgAvatar setFrame:CGRectMake(63, 26, sizeLabel.width + 10,sizeLabel.height + 10)];

    return comCellLeft;
}

-> 誰か助けてください。または、comCell.image.frame が間違ったフレームを表示する理由を知っています。

読んでくれてありがとう!

4

1 に答える 1

0

あなたの質問を正しく理解したかどうかわかりませんが、これを試してください:

(...)
//Image
comCell.imgAvatar = [UIImageView alloc] initWithFrame:CGRectMake(63, 26, sizeLabel.width + 10,sizeLabel.height + 10);
comCell.imgAvatar.image = [UIImage imageNamed:@"trang.png"];
(...)

それがあなたを助けたかどうか私に知らせてください。

于 2013-08-07T02:34:41.483 に答える