class ViewController: UIViewController {
var num = 1
@IBOutlet weak var image: UIImageView!
@IBOutlet weak var mylabel: UILabel!
@IBOutlet weak var PictureName: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
PictureName.text = "第1张照片"
// Do any additional setup after loading the view.
}
@IBAction func ChangeLabel(_ sender: Any) {
mylabel.text = "First Storyboard"
}
@IBAction func Next(_ sender: UIButton) {
num += 1
PictureName.text = "第\(num)张照片"
image.image = UIImage(named: "\(num)")
}
}
所有控件拽进去都是要用属性才能掉用
var image: UIImageView!
这代表导入了一个图片视图
image.image = UIImage(named: "\(num)")
这是设置图片显示
用segue跳转界面
1.先用视图连线,然后掉用方法
self.performSegue(withIdentifier: "tonext", sender: nil)
""表示的是连线的名称
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let identifier = "reusedCell"
let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath)
//重用机制,从所有开辟了内存的单元格中,选择一个具有同样标识符的空闲单元格
let label = cell.viewWithTag(1) as! UILabel?
//通过故事版中设置的表示值,获得单元格中的标签控件。
label?.text = fruit[(indexPath as NSIndexPath).row]
//根据表格行的编号,从数组中获得对应的字符串,从而设置标签的文字内容。
return cell
表格控件
let cellidentifier = "reseuedCell"
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellidentifier, for: indexPath)
let imageview = cell.viewWithTag(1) as! UIImageView
imageview.layer.opacity = 0.5
let imageName = image[(indexPath as NSIndexPath).row]
//根据表格行的编号,从数组中获得对应的图像名称
imageview.image = UIImage(named: imageName)
第一句代码显示的是获取标识符,很重要,锁定位置用
剩下的於上方的差不多.