开发者

Adding Image to Table Cell (iOS)

I am trying to do something similar to twitter开发者_高级运维 or Facebook.


- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{    
   static NSString* CellIdentifier = @"Cell";

   UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil)
      cell = [[[UITableViewCell alloc] UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

   cell.textLabel.text = @"I'm a UITableViewCell!";
   cell.imageView.image = [UIImage imageNamed:@"MyReallyCoolImage.png"];

   return cell;
}

Credit to Thomas Moore

adding images to UItableView


Well, to add an image to a table cell, you would add a UIImage to the image property of a subtitle UITableViewCell or your own custom Cell. I would read the doc on Customizing UITableViewCells at developer.apple.com.


Swift version:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

  let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell

  cell.textLabel.text = "I'm a UITableViewCell!";
  cell.textLabel.textColor = UIColor.whiteColor()
  cell.imageView.image = UIImage(named: "MyReallyCoolImage.png")

  return cell;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜