1.创建我们的第一个swift程序吧
2我们选择创建一个视图的故事版swift程序
3.我们在第一个视图这里来进行操作
4第一个swift程序我们来做一个按钮跟一个文本框吧\这样创建我们就可以在程序的其他地方使用他了
//
// ViewController.swift
// 第一个swift应用
//
// Created by 黄权浩 on 14-12-23.
// Copyright (c) 2014年 黄权浩. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//初始化一个文本框
var lb = UILabel(frame: CGRectMake(60, 100, 200, 40))
//文本框的背景颜色
lb.backgroundColor = UIColor.whiteColor()
//文本框的文字
lb.text = "我是一个swift文本框哦"
//文本框内内容的颜色
lb.textColor = UIColor.blackColor()
//文本框的对齐方式,默认为左对齐
lb.textAlignment = NSTextAlignment.Left
//加入到当前视图
self.view .addSubview(lb)
//初始化一个按钮
var bt: (UIButton) = (UIButton .buttonWithType(UIButtonType.Custom)) as (UIButton)
//按钮的样式
bt.frame = CGRectMake(40, 200, 200, 40)
bt .setTitle("按钮哦", forState: UIControlState.Normal)
bt .addTarget(self, action: "click", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(bt)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//
// ViewController.swift
// 第一个swift应用
//
// Created by 黄权浩 on 14-12-23.
// Copyright (c) 2014年 黄权浩. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
//按钮
var bt:UIButton!
//文本框
var lb:UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
bt = UIButton(frame: CGRectMake(40, 200, 200, 40))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}