Set own cell accessory type

Vpor picture Vpor · May 21, 2015 · Viewed 11.4k times · Source

I'd like to set my own cellAccessoryType (an image) in an UITableViewCell. Do you know how I can do this? I'm using Swift, Xcode 6.2 and iOS 8.2. Thank you for you help!

Answer

Adam Bardon picture Adam Bardon · May 21, 2015

Try this:

// first create UIImageView
var imageView : UIImageView
imageView  = UIImageView(frame:CGRectMake(20, 20, 100, 320))
imageView.image = UIImage(named:"image.jpg")

// then set it as cellAccessoryType
cell.accessoryView = imageView

PS: I strongly advise you to upgrade to XCode 6.3.2 and using iOS 8.3 SDK