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

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

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

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

效果

代码 自定义cell 的代码

  1. import UIKit
  2. import SnapKit
  3.  
  4. struct video {
  5. let image: String
  6. let title: String
  7. let source: String
  8.  
  9. }
  10.  
  11. class VideoViewCell: UITableViewCell {
  12. public var titleLabel:UILabel?
  13. public var picImageView:UIImageView?
  14. public var startImageView:UIImageView?
  15.  
  16. override func awakeFromNib() {
  17. super.awakeFromNib()
  18.  
  19. }
  20.  
  21. required init?(coder aDecoder: NSCoder) {
  22. super.init(coder: aDecoder)
  23. }
  24.  
  25. override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
  26. super.init(style: style, reuseIdentifier: reuseIdentifier);
  27. self.setUpUI()
  28. }
  29.  
  30. func setUpUI() {
  31.  
  32. self.picImageView = UIImageView.init()
  33. self.addSubview(self.picImageView!)
  34.  
  35. self.startImageView = UIImageView.init()
  36. startImageView?.image = UIImage.init(named: "playBtn")
  37. self.addSubview(self.startImageView!)
  38.  
  39. self.titleLabel = UILabel.init()
  40. self.titleLabel?.textColor = UIColor.white;
  41. self.titleLabel?.textAlignment = .center
  42. self.addSubview(self.titleLabel!)
  43.  
  44. self.picImageView?.snp.makeConstraints { (make) in
  45. make.top.equalTo(self).offset()
  46. make.left.equalTo(self).offset()
  47. make.width.equalTo(SCREEN_WIDTH)
  48. make.height.equalTo(self)
  49. }
  50.  
  51. self.startImageView?.snp.makeConstraints({ (make) in
  52. make.center.equalTo(self.snp.center)
  53. make.width.equalTo()
  54. make.height.equalTo()
  55. })
  56.  
  57. self.titleLabel?.snp.makeConstraints({ (make) in
  58. make.top.equalTo((self.startImageView?.snp.bottom)!).offset()
  59. make.width.equalTo(SCREEN_WIDTH)
  60. make.height.equalTo()
  61. })
  62.  
  63. }
  64.  
  65. override func setSelected(_ selected: Bool, animated: Bool) {
  66. super.setSelected(selected, animated: animated)
  67.  
  68. // Configure the view for the selected state
  69. }
  70.  
  71. }

控制器的代码

  1. import UIKit
  2. import AVKit
  3. import AVFoundation
  4.  
  5. let SCREEN_WIDTH = UIScreen.main.bounds.size.width
  6. let SCREEN_HEIGHT = UIScreen.main.bounds.size.height
  7.  
  8. class ViewController : UIViewController, UITableViewDataSource,UITableViewDelegate {
  9.  
  10. lazy var tableView = UITableView()
  11. let array:Array<Any> = []
  12. var data = [
  13.  
  14. video(image: "videoScreenshot01", title: "Introduce 3DS Mario", source: "Youtube - 06:32"),
  15. video(image: "videoScreenshot02", title: "Emoji Among Us", source: "Vimeo - 3:34"),
  16. video(image: "videoScreenshot03", title: "Seals Documentary", source: "Vine - 00:06"),
  17. video(image: "videoScreenshot04", title: "Adventure Time", source: "Youtube - 02:39"),
  18. video(image: "videoScreenshot05", title: "Facebook HQ", source: "Facebook - 10:20"),
  19. video(image: "videoScreenshot06", title: "Lijiang Lugu Lake", source: "Allen - 20:30")
  20.  
  21. ]
  22.  
  23. override func viewDidLoad() {
  24. super.viewDidLoad()
  25. self.tableView = UITableView(frame: CGRect(x: , y: , width: SCREEN_WIDTH, height: SCREEN_HEIGHT), style: .plain)
  26. self.tableView.dataSource = self
  27. self.tableView.delegate = self
  28. self.tableView.rowHeight = ;
  29. self.view.addSubview(tableView)
  30.  
  31. }
  32.  
  33. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  34. return data.count
  35. }
  36.  
  37. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  38. let customeIdntifier = "videoCell"
  39. var cell = tableView.dequeueReusableCell(withIdentifier: customeIdntifier) as? VideoViewCell
  40.  
  41. if cell == nil {
  42. cell = VideoViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier: customeIdntifier)
  43. }
  44.  
  45. let video = data[indexPath.row]
  46. cell?.titleLabel?.text = video.title
  47. cell?.picImageView?.image = UIImage.init(named: video.image)
  48. return cell!
  49. }
  50.  
  51. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  52. let playViewContoller = AVPlayerViewController()
  53. var playerView = AVPlayer()
  54.  
  55. let path = Bundle.main.path(forResource: "emoji zone", ofType: "mp4")
  56.  
  57. playerView = AVPlayer(url: URL(fileURLWithPath: path!))
  58.  
  59. playViewContoller.player = playerView
  60.  
  61. self.present(playViewContoller, animated: true) {
  62. playViewContoller.player?.play()
  63. }
  64.  
  65. }
  66.  
  67. override func didReceiveMemoryWarning() {
  68. super.didReceiveMemoryWarning()
  69. // Dispose of any resources that can be recreated.
  70. }
  71.  
  72. }

自学 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. Fix "Unable to lock the administration directory (/var/lib/dpkg/)" in Ubuntu

    While using the apt-get command or the relatively new APT package management tool in Ubuntu Linux or ...

  2. HashMap的数据机构是什么样的?

    参考:http://www.cnblogs.com/ITtangtang/p/3948406.html

  3. JS数组array常用方法

    JS数组array常用方法 1.检测数组 1)检测对象是否为数组,使用instanceof 操作符 if(value instanceof Array) { //对数组执行某些操作 } 2)获取对象的 ...

  4. 并不对劲的bzoj4652:loj2085:uoj221:p1587:[NOI2016]循环之美

    题目大意 对于已知的十进制数\(n\)和\(m\),在\(k\)进制下,有多少个数值上互不相等的纯循环小数,可以用\(x/y\)表示,其中 \(1\leq x\leq n,1\leq y\leq m\ ...

  5. BZOJ_1511_[POI2006]OKR-Periods of Words_KMP

    BZOJ_1511_[POI2006]OKR-Periods of Words_KMP Description 一个串是有限个小写字符的序列,特别的,一个空序列也可以是一个串. 一个串P是串A的前缀, ...

  6. 洛谷P4136 谁能赢呢?——博弈

    题目:https://www.luogu.org/problemnew/show/P4136 每个人有足够聪明,一定会把图走满: 所以n为偶数先手胜,n为奇数后手胜. 代码如下: #include&l ...

  7. pybot执行多条用例时,某一个用例执行失败,停止所有用例的执行

    问题: pybot执行多条用例时,某一个用例执行失败,停止所有用例的执行 解决办法: pybot -exitonfailure E:\robot\呼送项目\测试用例\基本流程\主流程.txt 参考文章 ...

  8. final的好处

    1.final关键字提高了性能.JVM和Java应用都会缓存final变量. 2.final变量可以安全的在多线程下进行共享,而不需要额外的同步开销. 3.使用final关键字,JVM会对方法,变量和 ...

  9. poj 1474 Video Surveillance 【半平面交】

    半平面交求多边形的核,注意边是顺时针给出的 //卡精致死于是换(?)了一种求半平面交的方法-- #include<iostream> #include<cstdio> #inc ...

  10. bzoj 1180: [CROATIAN2009]OTOCI【LCT】

    一道几乎是板子的LCT,但是沉迷数学很久时候突然1A了这道题还是挺开心的 #include<iostream> #include<cstdio> using namespace ...