UIKit框架-高级控件Swift版本: 3.UITableViewCell方法属性详解

UIKit框架-高级控件Swift版本: 3.UITableViewCell方法属性详解,第1张

概述前面我们知道了 UITableView 是怎么用得, 现在我们继续讲解和 UITableView密不可分的另一个空间 UITableViewCell. 1.UITableViewCell常用属性 UITableViewCell 显示的样式 enum UITableViewCellStyle : Int { case Default // 默认显示样式 case Value1 //

前面我们知道了 UItableVIEw 是怎么用得,现在我们继续讲解和 UItableVIEw密不可分的另一个空间 UItableVIEwCell.

1.UItableVIEwCell常用属性

UItableVIEwCell 显示的样式

enum UItableVIEwCellStyle : Int {    case Default // 默认显示样式    case Value1 // 样式一    case Value2 // 样式二    case SubTitle // 副标题样式}@H_403_28@  

UItableVIEwCell 选中的样式

enum UItableVIEwCellSelectionStyle : Int {    case None // 没有    case Blue // 蓝色    case Gray // 灰色    @availability(iOS,introduced=7.0)    case Default // 默认}@H_403_28@  

UItableVIEwCell 编辑的样式

enum UItableVIEwCellEditingStyle : Int {       case None // 没有    case Delete // 删除    case Insert // 添加}@H_403_28@  

UItableVIEwCell 辅助按钮的样式

enum UItableVIEwCellAccessoryType : Int {    case None // 没有按钮    case disclosureIndicator // 蓝色向右的箭头    case Detaildisclosurebutton // 蓝色向右的箭头以及信息按钮    case checkmark // 复选框    @availability(iOS,introduced=7.0)    case Detailbutton // 信息按钮}@H_403_28@  

UItableVIEwCell 常用属性

// 1.初始化 Cell 的 Style 以及标签名init(style: UItableVIEwCellStyle,reuseIDentifIEr: String?)// 2.设置 Cell 的 ImageVIEw 内容var imageVIEw: UIImageVIEw? { get }// 3.设置 Cell 的 textLabel 的内容var textLabel: UILabel? { get }// 4.设置 Cell 的 副标题内容var detailTextLabel: UILabel? { get }// 5.设置 Cell 的内容 VIEwvar contentVIEw: UIVIEw { get }// 6.设置 Cell 的背景 VIEwvar backgroundVIEw: UIVIEw?// 7.设置 Cell 被选中时的背景 VIEwvar selectedBackgroundVIEw: UIVIEw!// 8.设置 Cell 多选中得背景 VIEwvar multipleSelectionBackgroundVIEw: UIVIEw?// 9.设置 Cell 被选中时的 Stylevar selectionStyle: UItableVIEwCellSelectionStyle// 10.设置 Cell 编辑的 Stylevar editingStyle: UItableVIEwCellEditingStyle { get }// 11.设置 Cell 是否开启编辑状态var editing: Bool // 12.设置 Cell 的辅助按钮样式var accessoryType: UItableVIEwCellAccessoryType@H_403_28@    2.代码演示  

由于 tableVIEwCell 是不可以单独存在的,所以必须得依赖于 UItableVIEw

遵守 tableVIEw 代理协议以及数据源协议

class VIEwController: UIVIEwController,UItableVIEwDataSource,UItableVIEwDelegate {}@H_403_28@  

自定义 tableVIEw

func mytableVIEw() {        var tableVIEw = UItableVIEw(frame: self.vIEw.frame,style: UItableVIEwStyle.Plain)        tableVIEw.dataSource = self        tableVIEw.delegate = self        self.vIEw.addSubvIEw(tableVIEw)    }@H_403_28@  

实现数据源方法

func numberOfSectionsIntableVIEw(tableVIEw: UItableVIEw) -> Int {        return 1    }    func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int {        return 5    }@H_403_28@  

自定义 UItableVIEwCell

func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell {        // 1.自定义 UItableVIEwCell 的样式以及标签,reuseIDentifIEr 是 Cell 得标签,作用和 Tag 类似        var cell = UItableVIEwCell(style: UItableVIEwCellStyle.Value1,reuseIDentifIEr: "cell")        // 2.设置 UItableVIEwCell 的标题Label        cell.textLabel!.text = "我是 Cell"        // 3.设置 UItableVIEwCell 的简介Label        cell.detailTextLabel?.text = "Cell"        // 4.设置 UItableVIEwCell 的 imageVIEw 图片        cell.imageVIEw?.image = UIImage(named: "image_black.jpg")        // 5.设置 UItableVIEwCell 的编辑模式是否开启,以及是否执行动画效果        cell.setEditing(true,animated: true)        // 6.设置 UItableVIEwCell 的背景色        cell.backgroundcolor = UIcolor.greencolor()        // 7.设置 UItableVIEwCell 的编辑模式辅助按钮        cell.editingAccessoryType = UItableVIEwCellAccessoryType.disclosureIndicator        // 8.设置 UItableVIEwCell 被选中的样式        cell.selectionStyle = UItableVIEwCellSelectionStyle.Default        // 9.设置 UItableVIEwCell 分割线的位置        cell.separatorInset = UIEdgeInsetsMake(0,0,20)        // 10.设置 UItableVIEwCell 被选中时的背景VIEw        cell.selectedBackgroundVIEw = nil        // 11.设置 UItableVIEwCell 的辅助按钮样式        cell.accessoryType = UItableVIEwCellAccessoryType.disclosureIndicator        // 返回自定的 Cell        return cell    }@H_403_28@  

开启 tableVIEwCell 的编辑模式

func tableVIEw(tableVIEw: UItableVIEw,commitEditingStyle editingStyle: UItableVIEwCellEditingStyle,forRowAtIndexPath indexPath: NSIndexPath) {    }@H_403_28@    3.最终效果      

PS: UItableVIEwCell 是继承于 UIVIEw,所以 UIVIEw 里面的属性以及方法都是可以使用的.

好了,这次我们就讲到这里,下次我们继续~~

总结

以上是内存溢出为你收集整理的UIKit框架-高级控件Swift版本: 3.UITableViewCell方法/属性详解全部内容,希望文章能够帮你解决UIKit框架-高级控件Swift版本: 3.UITableViewCell方法/属性详解所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1088119.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存