2011-12-08 124 views
1

這是一種合適的方式還是有更好的解決方案?將UIImageView添加到自定義UITableView Cell

非常感謝!

Code(rowAtIndexPath)

UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(500, 50, 20, 20)]; 
     imageView.image = [UIImage imageNamed:@"Icon.png"]; 
     [cell addSubview:imageView]; 
+2

[http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html](http://developer。 apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html):) – Kjuly

+0

我只是使用[cell addSubview:imageView]。但對於其餘的它看起來不錯 – Novarg

回答

4

您應該添加您的意見,細胞的內容查看沒有電池的觀點。這裏有一個例子:

UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(500, 50, 20, 20)]; 
imageView.image = [UIImage imageNamed:@"Icon.png"]; 
[cell.contentView addSubview:imageView]; 
+0

我試過了。我在IB中創建了一個沒有contentView插座的原型單元。 (不要問我爲什麼......)使用原型的自定義.h文件和自定義圖像視圖的IBConnection解決了問題。我現在正在使用自定義按鈕(無論如何),因爲我決定用圖像捕捉觸摸事件。 – DAS

0

有我的代碼,它工作得很好,希望它可以幫助你。

UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(cell.contentView.frame.origin.x, cell.contentView.frame.size.height, 20, 20)]; 
imageView.image = [UIImage imageNamed:@"Icon.png"]; 
[cell.contentView addSubview:imageView]; 
1
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(cell.contentView.frame.origin.x, cell.contentView.frame.size.height, 20, 20)]; 

imageView.image = [UIImage imageNamed:@"Icon.png"]; 
[cell.contentView addSubview:imageView]; 

它是正確的。 UITableView的大列表。 如果您使用[cell addSubview:]它將看起來像閃爍大列表。

0

的SWIFT 3

let imgView : UIImageView = UIImageView(frame: CGRect(x: 500, y: 50, width: 70, height: 70)) 
    //CALayer for rounded image 
     let imageCALayer : CALayer = imgView.layer 
     imageCALayer.cornerRadius = 35 
     imageCALayer.masksToBounds = true 
     imgView.image = UIImage(string: "Icon.png") 
     cell.contentView.addSubview(imgView) 
相關問題