2012-03-05 42 views
0

所以我想知道是否可以在單元格的detailTextLabel中顯示一個小圖像? (我收到從URL圖像),我試了一下:你可以在detailTextLabel單元格中顯示一個小圖像嗎?

NSString *thumbs = [NSString stringWithFormat:@"%@", TableText3]; 
cell.detailTextLabel.text = thumbs; 

但出於明顯的原因無法正常工作。我也嘗試過:

UIImage *thumbs = [UIImage imageWithData:[NSData dataWithContentsOfURL: 
              [NSURL URLWithString:TableText3]]]; 
cell.detailTextLabel.text = thumbs; 

這也(顯然)不起作用,因爲我傳遞圖像到字符串參數。

令人驚訝我沒有找到在WWW上任何東西。 (搜索參數爲:「在detailTextLabel圖像」或圖片,或只是爲textLabel和形象,各種變化)

回答

1

而不是將圖像中的ImageView的屬性,你可以創建一個的UIImageView並將其放置在accessoryView的屬性:

UIImage  * thumbs; 
UIImageView * thumbsView; 
CGFloat  width; 

thumbs    = [UIImage imageWithData:[NSData dataWithContentsOfURL: 
           [NSURL URLWithString:TableText3]]]; 
thumbsView   = [[[UIImageView alloc] initWithImage:thumbs] autorelease]; 
width    = (cell.frame.size.height * thumbs.size.width)/thumbs.size.height; 
thumbsView.frame = CGRectMake(0, 0, width, cell.frame.size.height); 
cell.accessoryView = thumbsView; 

這將大小以適合內的圖像該單元格並將其放置在textLabel和detailTextLabel的右側。

2

你不能把它直接在標籤,因爲標籤只顯示文本。但是你可以使用UITableViewCell的imageView屬性。

cell.imageView = [[UIImageView alloc] initWithImage: thumbs]; 

https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html

+0

嗯,是的,但那麼它就會顯示在左上角,我希望我能在detailTextLabel顯示。 – Blade 2012-03-05 22:38:52

+0

我想你可以將imageView的框架更改爲 – Letrstotheprez 2012-03-05 22:40:56

+0

,但我希望能有更好的解決方案。不過謝謝。 – Blade 2012-03-05 22:42:53

1

更好的方法是不依靠內置的UITableViewCell類型和創建自己的電池框架上,並在細胞內的所需位置添加的所有標籤,查看圖片。然後你可以返回你的tableview的單元格。

相關問題