iOS TableVew 側(cè)滑效果~ Swift語言~demo

//聯(lián)系人:石虎QQ: 1224614774昵稱:嗡嘛呢叭咪哄

/**

注意點(diǎn): 1.看 GIF 效果圖.

2.看連線視圖的效果圖.

3.看實(shí)現(xiàn)代碼(直接復(fù)制實(shí)現(xiàn)效果).

*/

一、GIF 效果圖:

二、連線視圖的效果圖:

圖1:

圖2:

圖3:

三、實(shí)現(xiàn)代碼:

=============

======================================

控制器1:classViewController

//

//? ViewController.swift

//? TableVew 側(cè)滑效果~ swift語言

//

//? Created by 石虎 on 2017/8/21.

//? Copyright ? 2017年 shihu. All rights reserved.

//

import UIKit

class ViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource {

//創(chuàng)建全局的內(nèi)容

var tableView = UITableView()

var array = NSArray()

override func viewDidLoad() {

super.viewDidLoad()

tableView = UITableView(frame: self.view.bounds, style: .plain)

//設(shè)置代理

tableView.delegate = self

tableView.dataSource = self

//行高

tableView.rowHeight = 80

//添加到視圖中

self.view.addSubview(tableView)

array = ["01","02","03","04","05","06","07","08","09","010","011"]

}

//協(xié)議必須遵守的方法

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{

return array.count

}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{

//注冊cell

let identifier = "identtifier";

var cell=tableView.dequeueReusableCell(withIdentifier: identifier)

//緩存池

if(cell == nil){

cell=UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: identifier);

}

cell?.textLabel?.text = array[indexPath.row] as? String;

cell?.backgroundColor = #colorLiteral(red: 0.7254902124, green: 0.4784313738, blue: 0.09803921729, alpha: 1)

cell?.textLabel?.textColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)

cell?.accessoryType=UITableViewCellAccessoryType.disclosureIndicator

return cell!

}

// 更多按鈕設(shè)置

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?

{

//右側(cè)第一個(gè)按鈕

let actionOne = UITableViewRowAction(style: .normal, title: "我是第一個(gè)") {_,_ in

//提示框

let alert = UIAlertController(title:"第一個(gè)點(diǎn)擊成功??", message: "提醒", preferredStyle: UIAlertControllerStyle.alert)

self.present(alert, animated: true, completion: nil)

//消失? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //1秒

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {

self.presentedViewController?.dismiss(animated: false, completion: nil)

}

}

//背景顏色

actionOne.backgroundColor = #colorLiteral(red: 0.2588235438, green: 0.7568627596, blue: 0.9686274529, alpha: 1)

//右側(cè)第二個(gè)按鈕

let actionTwo = UITableViewRowAction(style: .normal, title: "我是第二個(gè)") {_,_ in

//提示框

let alert = UIAlertController(title:"第二個(gè)點(diǎn)擊成功??", message: "提醒", preferredStyle: UIAlertControllerStyle.alert)

self.present(alert, animated: true, completion: nil)

//消失? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //1秒

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {

self.presentedViewController?.dismiss(animated: false, completion: nil)

}

}

//背景顏色

actionTwo.backgroundColor = #colorLiteral(red: 0.2745098174, green: 0.4862745106, blue: 0.1411764771, alpha: 1)

return [actionOne, actionTwo]

}

}


謝謝!!!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容