设置自己的电池配件类型

Vpo*_*por 5 cell uitableview accessorytype swift xcode6

我想在UITableViewCell中设置我自己的cellAccessoryType(图像).你知道我怎么做吗?我正在使用Swift,Xcode 6.2和iOS 8.2.谢谢你的帮助!

Ada*_*don 15

试试这个:

// 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
Run Code Online (Sandbox Code Playgroud)

PS:我强烈建议您升级到XCode 6.3.2并使用iOS 8.3 SDK


Shm*_*idt 9

我假设你想点击附件视图,所以我用按钮提供这个答案.如果没有,请使用带有imageView的shargath答案.

var saveButton = UIButton.buttonWithType(.Custom) as UIButton
        saveButton.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
        saveButton.addTarget(self, action: "accessoryButtonTapped:", forControlEvents: .TouchUpInside)
        saveButton.setImage(UIImage(named: "check-circle"), forState: .Normal)
        cell.accessoryView = saveButton as UIView

func accessoryButtonTapped(sender:UIButton) {

}
Run Code Online (Sandbox Code Playgroud)