美文网首页
swift简单代码记录

swift简单代码记录

作者: 私心丶 | 来源:发表于2017-03-20 10:06 被阅读0次

发现会OC的 看swift还是比较简单的,只是不用分号很不习惯,仅此记录下学习时候写的简单代码

创建按钮

let button = UIButton(type: .custom)

button.frame = CGRect(x: 100, y: 100, width: 100, height: 100)

view.addSubview(button)

button.backgroundColor = UIColor.blue

button .addTarget(self, action: #selector(click), for: .touchUpInside)

实现Button点击方法

func click() -> () {

}

创建imageView

let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height))

imageView.backgroundColor = UIColor.red

imageView.image = UIImage(named: "timg.jpeg")

view .addSubview(imageView)

创建tableView

let tab = UITableView(frame:view.frame, style: .plain)

tab.delegate = self

tab.dataSource = self

view.addSubview(tab)

tab.register(UITableViewCell.self, forCellReuseIdentifier: "cell")

//MARK: delegate

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return 10

}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView .dequeueReusableCell(withIdentifier: "cell", for: indexPath)

cell.textLabel?.text = "\(indexPath.row)"

cell.selectionStyle = .none

cell.contentView.backgroundColor = UIColor.brown

return cell

}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

return 44

}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

print("\(indexPath.row)")

}

相关文章

  • swift简单代码记录

    发现会OC的 看swift还是比较简单的,只是不用分号很不习惯,仅此记录下学习时候写的简单代码 创建按钮 let ...

  • 在Objc项目中调用Swift

    之前的文字中记录了在Swift项目中调用OC的相关代码,比较简单直接 传送门 但是在OC中调用swift代码则不是...

  • iOS 点赞头像列表叠加效果

    直接上效果图 swift int转cgfloat报错,进行转换:CGFloat 直接上代码 虽然实现很简单还是记录...

  • Swift5.2 - UISearchController的简单

    Swift - UISearchController的简单使用 记录下UISearchController的简单使...

  • swift之tableView

    抽空继续研究swift,本文简单介绍用swift创建tableView,大神请无视?代码如下

  • swift代码实现TableView

    前言 继续接着上一篇OC代码实现TableView来写我们的swift代码,通过swift代码实现一个简单的Tab...

  • 01 Swift最基本的语法变化

    本swift系列笔记更新记录 2017.6.20 -- 基于swift3.1的语法更新代码。 导入框架 定义标识符...

  • swift3.0----UITableView

    简单介绍UITableView在swift3.0中基本用法。(代码如图)

  • 学习Swift

    LearnSwiftEasily 用心记录自己学习Swift的心得体会,让学习变得简单与快乐! Swift基础语法...

  • Swift:基础(十五)函数

    Swift 函数 Swift 函数用来完成特定任务的独立的代码块。 Swift使用一个统一的语法来表示简单的C语言...

网友评论

      本文标题:swift简单代码记录

      本文链接:https://www.haomeiwen.com/subject/qpsbnttx.html