iOS TableVew 侧滑效果~ Swift语言~demo
//联系人:石虎 QQ: 1224614774昵称:嗡嘛呢叭咪哄
/**
注意点: 1.看 GIF 效果图.
2.看连线视图的效果图.
3.看实现代码(直接复制实现效果).
4.详细请看:http://www.jianshu.com/p/a7d8774eb1c8
*/
一、GIF 效果图:
二、连线视图的效果图:
图1:
图2:
图3:
三、实现代码:
=============
======================================
控制器1: class ViewController
//
// ViewController.swift
// TableVew 侧滑效果~ swift语言
//
// Created by 石虎 on 2017/8/21.
// Copyright © 2017年 shihu. All rights reserved.
//
import UIKit
class ViewController:UIViewController ,UITableViewDelegate,
UITableViewDataSource {
//创建全局的内容
var tableView =UITableView()
var array =NSArray()
overridefunc viewDidLoad() {
super.viewDidLoad()
tableView =UITableView(frame:self.view.bounds,
style: .plain)
//设置代理
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"]
}
//协议必须遵守的方法
func tableView(_ tableView:UITableView,
numberOfRowsInSection section: Int) ->Int{
returnarray.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!
}
// 更多按钮设置
func tableView(_ tableView:UITableView, editActionsForRowAt indexPath:IndexPath) -> [UITableViewRowAction]?
{
//右侧第一个按钮
let actionOne =UITableViewRowAction
(style: .normal, title:"我是第一个") {_,_in
//提示框
let alert =UIAlertController
(title:"第一个点击成功