swift系统学习控件篇:UITableView+UICollectionView
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码:
UITableView:
//
// ViewController.swift
// UItableView-swift
//
// Created by shaoting on 16/3/23.
// Copyright © 2016年 9elephas. All rights reserved.
// import UIKit class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{
var ary:[String] = ["","",""];
override func viewDidLoad() {
super.viewDidLoad()
//定义一个UITableView
let mytableView = UITableView(frame: CGRectMake(, , UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height), style: UITableViewStyle.Plain)
self.view.addSubview(mytableView)
mytableView.delegate = self
mytableView.dataSource = self
mytableView.backgroundColor = UIColor.whiteColor()
mytableView.rowHeight =
// Do any additional setup after loading the view, typically from a nib.
}
//实现UITableViewDataSource必须实现的两个方法
//行数
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return
}
//返回cell
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = "少停"
if indexPath.row % == {
cell.imageView?.image = UIImage(named: "")
}else{
cell.imageView?.image = UIImage(named: "")
}
return cell
}
//section个数
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return
}
//页眉
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == {
return ""
}else if section == {
return ""
}else{
return ""
}
}
//页脚
func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return "..."
}
//右侧索引
func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
return ary
}
//可以编辑
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
if indexPath.section == {
return false
}else{
return true
}
}
//可以移动
func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true;
}
//选中
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.section == {
print("选中1区第\(indexPath.row)行")
}else if indexPath.section == {
print("选中2区第\(indexPath.row)行")
}else{
print("选中3区第\(indexPath.row)行")
}
} override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} }
UICollectionView:
//
// ViewController.swift
// CollectionView
//
// Created by shaoting on 16/3/25.
// Copyright © 2016年 9elephas. All rights reserved.
// import UIKit class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
var collectionView : UICollectionView?
var dataAry = NSMutableArray()
override func viewDidLoad() {
super.viewDidLoad()
let flowLayout = UICollectionViewFlowLayout()
flowLayout.itemSize = CGSizeMake(, )
flowLayout.scrollDirection = UICollectionViewScrollDirection.Vertical // 设置垂直显示
flowLayout.sectionInset = UIEdgeInsetsMake(, , , ) //设置边距
flowLayout.minimumLineSpacing = //设置相邻layout的上下
flowLayout.minimumInteritemSpacing = //设置相邻layout的左右
flowLayout.headerReferenceSize = CGSizeMake(, ) collectionView = UICollectionView(frame: CGRect(x: , y: , width: self.view.frame.size.width, height: self.view.frame.size.height), collectionViewLayout: flowLayout)
collectionView?.delegate = self
collectionView?.dataSource = self
collectionView?.alwaysBounceVertical = true
self.view.addSubview(collectionView!)
collectionView?.backgroundColor = UIColor.whiteColor()
collectionView?.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell") //注册一个cell // Do any additional setup after loading the view, typically from a nib.
} func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{ return
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as UICollectionViewCell
cell.backgroundColor = UIColor.redColor() return cell
} override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} }
源码下载地址:
UITableView:
https://github.com/pheromone/UItableView-swift
http://download.csdn.net/detail/shaoting19910730/9474696
UICollectionView
http://download.csdn.net/detail/shaoting19910730/9474700
https://github.com/pheromone/CollectionView
swift学习网站;
swift系统学习控件篇:UITableView+UICollectionView的更多相关文章
- swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...
- swift系统学习控件篇:UIProgressView+NSTimer+UIstepper+UIAlertController
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIProgressView+NSTimer+UIstepper UIStepper UIP ...
- 一步一步学android之控件篇——ScrollView
一个手机的屏幕大小是有限的,那么我要显示的东西显示不下怎么办?这就会使用到ScrollView来进行滚动显示,他的定义如下: 可以看到ScrollView是继承于FrameLayout的,所以Scro ...
- 用swift开发仪表盘控件(一)
苹果swift刚刚推出不久,接触到这个语言是一个偶然的机会,无聊之余随便看了下它的语法: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveW5tYW95b2 ...
- DevExpress学习系列(控件篇):GridControl的基本应用
一般属性设置 不显示分组框:Gridview->Option View->Show Group Panel=false 单元格不可编辑:gridcontrol -->gridview ...
- WPF学习笔记 控件篇 属性整理【1】FrameworkElement
最近在做WPF方面的内容,由于好多属性不太了解,经常想当然的设置,经常出现自己未意料的问题,所以感觉得梳理下. ps:先补下常用控件的类结构,免得乱了 .NET Framework 4.5 Using ...
- openlayers4 入门开发系列之地图导航控件篇(附源码下载)
前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...
- [Swift]键盘遮挡控件
键盘遮挡控件: super.viewDidLoad(){ // Do any additional setup after loading the view, typically from a nib ...
- 用swift开发仪表盘控件(二)
二.代码分析 这个控件本质就是从UIView继承的一个类而已.所以整个代码事实上就是一个定制的UIView类. 依据UIView的规则进行例如以下初始化: required init(coder aD ...
随机推荐
- hdu----(2848)Repository(trie树变形)
Repository Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDUOJ-----(1162)Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- iOS开发之内购-AppStore
本文会给大家详细介绍iOS内购,虽然之前网上也有内购的教程,但是还不够详细,我重新整理出一份教程,希望对大家有所帮助. 基于Xcode7.1.1版本,模拟器iphone6,9.1系统.部分地方直接摘自 ...
- IntelliJ IDEA 中properties中文显示问题
- 理解Servlet过滤器 (javax.servlet.Filter)
过滤器(Filter)的概念 过滤器位于客户端和web应用程序之间,用于检查和修改两者之间流过的请求和响应. 在请求到达Servlet/JSP之前,过滤器截获请求. 在响应送给客户端之前,过滤器截获响 ...
- 查看Linux软件信息
查看系统发型版本 1. 对于linux系统而已,有成百上千个发行版.对于发行版的版本号查看方法 如以centos为例.输入lsb_release -a即可 该命令适用于所有的linux,包括Redha ...
- 阮一峰:RSA算法原理(一)
今天看到一篇好文章,关于加密算法,收藏了觉得不过瘾,还是自己贴一遍,也能加深一下印象. 原文链接:http://www.ruanyifeng.com/blog/2013/06/rsa_algorith ...
- SecureCRT快捷键
ctrl + a : 移动光标到行首ctrl + e :移动光标到行尾crtl + b: 光标前移1个字符crtl + f : 光标后移1个字符 crtl + h : 删除光标之前的一个字符c ...
- 452. Minimum Number of Arrows to Burst Balloons——排序+贪心算法
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- Junit4的简单使用
junit4的简单使用 测试套件的使用 测试类1 package com.westward; import static org.junit.Assert.*; import org.junit.Te ...