2011-03-16 64 views
0

我敢肯定,這是很簡單,但我無法找到關於它的任何文件。在我的UITableViewXcode中的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; 

} 

回答

0

試試這個

cell.accessoryView = [UIImage的imageNamed:@ 「tableicon.png」];

2

不是將圖像添加爲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]; 

這還有一個額外的好處,即在方向改變時自動重新調整。