做了这个小demo 之后  感觉OC 和swift 还是有很大的差别的 自己还是要去多看些swift的语法 用的不是很熟练

1.这个demo 的资源文件 我都是用原工程的

2.同样的自定义cell 的时候 用的是“SnapKit”这个库

3.其实这一个demo的主要就是自定义cell,思想和OC 是一样的 总感觉swift写的是那么的别扭,可能还是不熟悉语法吧,还是要多看多练

效果

代码 自定义cell 的代码

import UIKit
import SnapKit struct video {
let image: String
let title: String
let source: String } class VideoViewCell: UITableViewCell {
public var titleLabel:UILabel?
public var picImageView:UIImageView?
public var startImageView:UIImageView? override func awakeFromNib() {
super.awakeFromNib() } required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
} override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier);
self.setUpUI()
} func setUpUI() { self.picImageView = UIImageView.init()
self.addSubview(self.picImageView!) self.startImageView = UIImageView.init()
startImageView?.image = UIImage.init(named: "playBtn")
self.addSubview(self.startImageView!) self.titleLabel = UILabel.init()
self.titleLabel?.textColor = UIColor.white;
self.titleLabel?.textAlignment = .center
self.addSubview(self.titleLabel!) self.picImageView?.snp.makeConstraints { (make) in
make.top.equalTo(self).offset()
make.left.equalTo(self).offset()
make.width.equalTo(SCREEN_WIDTH)
make.height.equalTo(self)
} self.startImageView?.snp.makeConstraints({ (make) in
make.center.equalTo(self.snp.center)
make.width.equalTo()
make.height.equalTo()
}) self.titleLabel?.snp.makeConstraints({ (make) in
make.top.equalTo((self.startImageView?.snp.bottom)!).offset()
make.width.equalTo(SCREEN_WIDTH)
make.height.equalTo()
}) } override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated) // Configure the view for the selected state
} }

控制器的代码

import UIKit
import AVKit
import AVFoundation let SCREEN_WIDTH = UIScreen.main.bounds.size.width
let SCREEN_HEIGHT = UIScreen.main.bounds.size.height class ViewController : UIViewController, UITableViewDataSource,UITableViewDelegate { lazy var tableView = UITableView()
let array:Array<Any> = []
var data = [ video(image: "videoScreenshot01", title: "Introduce 3DS Mario", source: "Youtube - 06:32"),
video(image: "videoScreenshot02", title: "Emoji Among Us", source: "Vimeo - 3:34"),
video(image: "videoScreenshot03", title: "Seals Documentary", source: "Vine - 00:06"),
video(image: "videoScreenshot04", title: "Adventure Time", source: "Youtube - 02:39"),
video(image: "videoScreenshot05", title: "Facebook HQ", source: "Facebook - 10:20"),
video(image: "videoScreenshot06", title: "Lijiang Lugu Lake", source: "Allen - 20:30") ] override func viewDidLoad() {
super.viewDidLoad()
self.tableView = UITableView(frame: CGRect(x: , y: , width: SCREEN_WIDTH, height: SCREEN_HEIGHT), style: .plain)
self.tableView.dataSource = self
self.tableView.delegate = self
self.tableView.rowHeight = ;
self.view.addSubview(tableView) } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
} func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let customeIdntifier = "videoCell"
var cell = tableView.dequeueReusableCell(withIdentifier: customeIdntifier) as? VideoViewCell if cell == nil {
cell = VideoViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier: customeIdntifier)
} let video = data[indexPath.row]
cell?.titleLabel?.text = video.title
cell?.picImageView?.image = UIImage.init(named: video.image)
return cell!
} func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let playViewContoller = AVPlayerViewController()
var playerView = AVPlayer() let path = Bundle.main.path(forResource: "emoji zone", ofType: "mp4") playerView = AVPlayer(url: URL(fileURLWithPath: path!)) playViewContoller.player = playerView self.present(playViewContoller, animated: true) {
playViewContoller.player?.play()
} } override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} }

自学 iOS - 三十天三十个 Swift 项目 第三天的更多相关文章

  1. 自学 iOS – 三十天三十个 Swift 项目

    自学 iOS – 三十天三十个 Swift 项目 github源码地址:https://github.com/allenwong/30DaysofSwift

  2. 自学 iOS - 三十天三十个 Swift 项目 第一天

    最近公司项目不是很忙,偶然间看到编程语言排行榜,看到swift 已经排到前10了,然OC排名也越来越后了,感觉要上车了,虽然现在项目都是用OC写的,但是swift是一种趋势.在网上看到"自学 ...

  3. 自学 iOS - 三十天三十个 Swift 项目 第二天

    继续做仿造着别人的第二个 1.首先下载 一些字体 网上搜索 "造字工房" 2.把下载的相应字体文件放到工程之中,就Ok了 不多说 效果如下 可以下面这个方法 检索项目里面所有的字体 ...

  4. swift项目第三天:手写代码搭建主框架

    一:先配置环境:自定义Log输出(DEBUG 和 release模式),并屏蔽后台多余的打印信息 1:屏蔽后台多余的打印信息:如果写了OS_ACTIVITY_MODE = disable 还是不行.把 ...

  5. 【Android Studio安装部署系列】三十四、将Eclipse项目导入到Android Studio中

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 我采用的是笨方法:新创建Android Studio项目,然后将Eclipse项目中的目录一一复制到Android Studio项目 ...

  6. 第三十二章 System V信号量(三)

    n哲学家进餐问题描述有五个哲学家,他们的生活方式是交替地进行思考和进餐,n哲学家们共用一张圆桌,分别坐在周围的五张椅子上,在圆桌上有五个碗和五支筷子,n平时哲学家进行思考,饥饿时便试图取其左.右最靠近 ...

  7. 机器学习实战基础(三十六):随机森林 (三)之 RandomForestClassifier 之 重要属性和接口

    重要属性和接口 至此,我们已经讲完了所有随机森林中的重要参数,为大家复习了一下决策树的参数,并通过n_estimators,random_state,boostrap和oob_score这四个参数帮助 ...

  8. iOS开发之Todo List for Swift项目

    一直从事Windows Phone开发,但对iOS开发一直有所好奇,于是在MBP到手之际,顺手安装了Xcode.移动互联网开发的相似性,使得我能快速地了解和认识了iOS的开发框架体系,在看完了Appl ...

  9. FreeSql (三十)读写分离

    FreeSql 支持数据库读写分离,本功能是客户端的读写分离行为,数据库服务器该怎么配置仍然那样配置,不受本功能影响,为了方便描术后面讲到的[读写分离]都是指客户端的功能支持. 各种数据库的读写方案不 ...

随机推荐

  1. 【剑指offer】数组中仅仅出现一次的数字(1)

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/27649027 题目描写叙述: 一个整型数组里除了两个数字之外.其它的数字都出现了两次. 请 ...

  2. 2016/3/20 数组定义 数组遍历 超全局数组 数组元素设置(in_array() 、array_reverse()、count()、array_unique()、unset()、array_values、array_merge、array_push) 列表实例

    一.数组定义 php数组与其他语言的数组的不同: 其他例如java语言 :同一种类型数据的集合. php:数组可以存储任何类型的数据.同一个数组中可以放int类型也可以放string类型 ①索引数组的 ...

  3. CXF拦截器(Interceptor)LoggingInInterceptor

    Interceptor是CXF架构中一个重要的功能.你可以在不对核心模块进行修改的情况下,动态添加很多功能(你可以想象Struts2拦截器的优点).这对于CXF这个以处理消息为中心的服务框架来说是非常 ...

  4. Deep Learning 27:Batch normalization理解——读论文“Batch normalization: Accelerating deep network training by reducing internal covariate shift ”——ICML 2015

    这篇经典论文,甚至可以说是2015年最牛的一篇论文,早就有很多人解读,不需要自己着摸,但是看了论文原文Batch normalization: Accelerating deep network tr ...

  5. Linux进程间通信——使用信号量【转】

    本文转载自:http://blog.csdn.net/ljianhui/article/details/10243617 这篇文章将讲述别一种进程间通信的机制——信号量.注意请不要把它与之前所说的信号 ...

  6. 【Selenium】idea导入eclisp项目的问题

    ①导入:file→new→Project from exiting 选择ecliesp 然后next就可以 ②添加依赖:每个包都要加,引用其他包的类,也要添加依赖 setting选择junit4

  7. Spring Cloud 与 Dubbo 区别

      Dubbo Spring Cloud 服务注册中心 Zookeeper Spring Cloud Netflix Eureka 服务调用方式 RPC REST API 服务监控 Dubbo-mon ...

  8. 从事UNIX/LInux服务器编程最方便的代码编译工具------(eclipse for c/c++)、(FileZilla)、(Secure CRT) 这三种一定要一起使用 之1

    今天主要是将前几天搞的Linux学习的心得写出来,希望帮助更多的人进行,方便从事Unix和Linux编程的同行和刚入门者.主要介绍三种工具并给出安装过程,请大家不必怀疑这个博文,此博文是我自己原创.请 ...

  9. UVa 12716 && UVaLive 6657 GCD XOR (数论)

    题意:给定一个 n ,让你求有多少对整数 (a, b) 1 <= b <= a 且 gcd(a, b) = a ^ b. 析:设 c = a ^ b 那么 c 就是 a 的约数,那么根据异 ...

  10. python pep8 命令规范

    命名规范:总体原则,新编代码必须按下面命名风格进行,现有库的编码尽量保持风格.1 尽量单独使用小写字母‘l’,大写字母‘O’等容易混淆的字母.2 模块命名尽量短小,使用全部小写的方式,可以使用下划线. ...