Выровнять изображение ячейки xcode uitableview - PullRequest
0 голосов
/ 16 марта 2011

Я уверен, что это очень просто, но я не могу найти документацию по этому поводу ..

в моем uitableview у меня есть текстовые метки, выровненные по правому краю (мое приложение в heberw, что rtl) я пытаюсь добавить изображение в ячейку к праву текстовой метки, не повезло, пока изображение выровнено по левому краю и я не могу найти способ выровнять его по правой стороне ячейки

вот мой код:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }


        cell.imageView.image = [UIImage imageNamed:@"tableicon.png"];

    NSString *cellValue = [[stories objectAtIndex:indexPath.row] objectForKey:@"ArticleTitle"];
    cell.textLabel.text = cellValue;
    cell.textLabel.textAlignment = UITextAlignmentRight;
    cell.textLabel.font = [UIFont systemFontOfSize:17];
        cell.textLabel.numberOfLines = 2;

    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;

}

Ответы [ 2 ]

2 голосов
/ 24 января 2012

Вместо добавления изображения в качестве подпредставления вашего UITableViewCell добавьте контейнер с выровненными по праву подпредставлениями.

UIImageView *pic = myImageView;
UIView *picContainer = [[UIView alloc] initWithFrame:cell.frame];
picContainer.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
picContainer.contentMode = UIViewContentModeRight;
pic.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
pic.center = CGPointMake(picContainer.frame.size.width-70, picContainer.frame.size.height/2);
[picContainer addSubview:pic];
[cell.contentView addSubview:picContainer];

Это дает дополнительное преимущество автоматической перенастройки при изменении ориентации.

0 голосов
/ 07 апреля 2011

попробуйте это

cell.accessoryView = [UIImage imageNamed: @ "tableicon.png"];

...