# 学Swift挣美元实战开发篇之01 编写你的第一个真实APP

之前的文章主要介绍swift的语法,本篇将带领大家从UI层面学习iOS开发

学Swift挣美元实战开发篇之01 编写你的第一个真实APP

效果

第一个app

功能介绍

手工创建一个label和view,并将他们添加到界面上。

第一步 创建一个single view app

第二步 将下面代码敲击到ViewController.swift里

class ViewController: UIViewController {
  var redView:UIView!
  var label:UILabel!
  
  override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = UIColor.yellow
    redView = UIView(frame: CGRect(x: 0, y: 0,
                                   width: view.bounds.width, height: view.bounds.height / 2))
    redView.backgroundColor = UIColor.red
    view.addSubview(redView)
    
    
    label = UILabel(frame:
      CGRect(x: 20, y: self.view.bounds.height / 2,
             width: 20, height: 20))
    view.addSubview(label)
    label.text = "Hello World"
    label.font = label.font.withSize(40)
    label.sizeToFit()
  }
  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }
}

第三步 运行

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容