swift初见
来源:互联网 发布:matlab中蚁群算法 编辑:程序博客网 时间:2024/05/31 13:14
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor .yellowColor();
self.addView();
self.addButton();
self.addButton1();
self.createLabel()
}
func createLabel() {
let label = UILabel();
label.text = "1234"
label.frame = CGRectMake(100, 80, 100, 50);
label.textAlignment = NSTextAlignment.Center;
label.textColor = UIColor.blackColor()
self.view.addSubview(label);
}
func addButton() {
let clickButton = UIButton();
clickButton.frame = CGRectMake(100, 100, 100, 100);
clickButton.backgroundColor = UIColor.redColor();
clickButton .setTitle("clock", forState: UIControlState.Normal);
clickButton.addTarget(self, action: Selector("click:"), forControlEvents: UIControlEvents.TouchUpInside);
self.view .addSubview(clickButton);
}
func addButton1() {
let addButton1 = UIButton()
addButton1.frame = CGRectMake(20, 200, 50, 60)
addButton1.backgroundColor = UIColor.brownColor();
addButton1.addTarget(self, action: Selector("tap:"), forControlEvents: UIControlEvents.TouchUpInside)
addButton1.tag = 101;
self.view .addSubview(addButton1);
}
func click(sender:UIButton) {
let alertController = UIAlertController(title: "alert", message: "my is young", preferredStyle: UIAlertControllerStyle.Alert)
let alertAction = UIAlertAction(title: ">>>>>", style: UIAlertActionStyle.Destructive, handler: nil)
let alertAction1 = UIAlertAction(title: "click", style: UIAlertActionStyle.Cancel, handler: nil)
let alertAction2 = UIAlertAction(title: "[uhk", style: UIAlertActionStyle.Default, handler: nil)
alertController.addAction(alertAction2)
alertController.addAction(alertAction1)
alertController.addAction(alertAction)
self.presentViewController(alertController, animated: true, completion: nil)
print(sender.tag)
}
func tap(sender:UIButton) {
let alertController = UIAlertController(title: "second alert", message: nil, preferredStyle: UIAlertControllerStyle.Alert)
// let alertAction = UIAlertAction();
alertController.addTextFieldWithConfigurationHandler { (UITextField) -> Void in
print(sender.tag)
}
let alertAction = UIAlertAction(title: "yes", style: UIAlertActionStyle.Default, handler: nil)
let alertAction2 = UIAlertAction(title: "No", style: UIAlertActionStyle.Cancel, handler: nil)
alertController.addAction(alertAction)
alertController.addAction(alertAction2)
self.presentViewController(alertController, animated: true, completion: nil)
}
func addView() {
let view = UIView();
view.frame = CGRectMake(100, 100, 200, 300);
view.backgroundColor = UIColor.blackColor();
self.view.addSubview(view);
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true);
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor .yellowColor();
self.addView();
self.addButton();
self.addButton1();
self.createLabel()
}
func createLabel() {
let label = UILabel();
label.text = "1234"
label.frame = CGRectMake(100, 80, 100, 50);
label.textAlignment = NSTextAlignment.Center;
label.textColor = UIColor.blackColor()
self.view.addSubview(label);
}
func addButton() {
let clickButton = UIButton();
clickButton.frame = CGRectMake(100, 100, 100, 100);
clickButton.backgroundColor = UIColor.redColor();
clickButton .setTitle("clock", forState: UIControlState.Normal);
clickButton.addTarget(self, action: Selector("click:"), forControlEvents: UIControlEvents.TouchUpInside);
self.view .addSubview(clickButton);
}
func addButton1() {
let addButton1 = UIButton()
addButton1.frame = CGRectMake(20, 200, 50, 60)
addButton1.backgroundColor = UIColor.brownColor();
addButton1.addTarget(self, action: Selector("tap:"), forControlEvents: UIControlEvents.TouchUpInside)
addButton1.tag = 101;
self.view .addSubview(addButton1);
}
func click(sender:UIButton) {
let alertController = UIAlertController(title: "alert", message: "my is young", preferredStyle: UIAlertControllerStyle.Alert)
let alertAction = UIAlertAction(title: ">>>>>", style: UIAlertActionStyle.Destructive, handler: nil)
let alertAction1 = UIAlertAction(title: "click", style: UIAlertActionStyle.Cancel, handler: nil)
let alertAction2 = UIAlertAction(title: "[uhk", style: UIAlertActionStyle.Default, handler: nil)
alertController.addAction(alertAction2)
alertController.addAction(alertAction1)
alertController.addAction(alertAction)
self.presentViewController(alertController, animated: true, completion: nil)
print(sender.tag)
}
func tap(sender:UIButton) {
let alertController = UIAlertController(title: "second alert", message: nil, preferredStyle: UIAlertControllerStyle.Alert)
// let alertAction = UIAlertAction();
alertController.addTextFieldWithConfigurationHandler { (UITextField) -> Void in
print(sender.tag)
}
let alertAction = UIAlertAction(title: "yes", style: UIAlertActionStyle.Default, handler: nil)
let alertAction2 = UIAlertAction(title: "No", style: UIAlertActionStyle.Cancel, handler: nil)
alertController.addAction(alertAction)
alertController.addAction(alertAction2)
self.presentViewController(alertController, animated: true, completion: nil)
}
func addView() {
let view = UIView();
view.frame = CGRectMake(100, 100, 200, 300);
view.backgroundColor = UIColor.blackColor();
self.view.addSubview(view);
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true);
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
0 0
- Swift初见
- Swift 初见
- Swift初见
- Swift初见
- swift初见
- Swift初见
- swift初见
- 【Swift初见】Swift数组
- 【Swift初见】Swift字典
- 【Swift初见】Swift继承
- swift之初见
- 【Swift初见】SourceKitService Terminated
- swift语言初见
- 初见swift--基本类型
- 初见Swift----基础一
- Swift初见(一)
- 【note】Swift初见笔记
- 【Swift初见】Swift数组(二)
- 收藏的文章
- 为网站加入Drupal星球制作RSS订阅源
- 中国智慧景区联盟今日成立 发布《中国智慧景区九寨沟宣言》
- DBA的技能图谱
- YARN文档概述
- swift初见
- iptables的详细介绍及配置方法
- oracle的批量插入
- Android使用shape设置虚线、圆角、渐变
- 深入分析JavaWeb 13 -- jsp指令详解
- 基于@Aspect的AOP注解配置
- 基于注解的SpringMVC简单介绍
- Iptables 指南 1.1.19
- BZOJ2190: [SDOI2008]仪仗队