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)
第一句代碼顯示的是擷取辨別符,很重要,鎖定位置用
剩下的於上方的差不多.