swift资源库-2-初识UI
来源:互联网 发布:linux ntp服务器配置 编辑:程序博客网 时间:2024/06/05 20:13
class ViewController: UIViewController {
let View_W = UIScreen.mainScreen().bounds.size.width
let View_H = UIScreen.mainScreen().bounds.size.height
override func viewDidLoad() {
super.viewDidLoad()
//
view.backgroundColor = UIColor.grayColor()
//UIVIEW
//let 修饰 v 并且赋值,该常量的内存地址不允许修改,但是可以修改其内部的属性
//常量&变量的使用原则:尽量先用 let,只有需要变的时候,再用 var,能够更加安全
let v = UIView(frame: CGRectMake(0,0,180,100))
v.backgroundColor = UIColor.redColor()
v.alpha = 0.6
v.center = CGPointMake(View_W/2, View_H/8)
view.addSubview(v)
text()
}
func text(){
let b = UIButton(frame: CGRectMake(30,330,120,40))
b.setTitle("点击", forState: UIControlState.Normal)
b.setTitle("高亮", forState: UIControlState.Highlighted)
b.setTitle("选择", forState: UIControlState.Selected)
b.titleLabel?.text="normal"
b.tag = 12;
b.addTarget(self, action:Selector(btnclicked(b)), forControlEvents: UIControlEvents.TouchUpInside)
b .setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
b.backgroundColor = UIColor.yellowColor()
b.center = CGPointMake(View_W/2, View_H/3.5)
view.addSubview(b)
}
// 按钮点击事件
func btnclicked(sender:UIButton){
if sender.tag == 5 {
let alert = UIAlertController(title: "提醒", message: "点击",preferredStyle: UIAlertControllerStyle.Alert)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
- swift资源库-2-初识UI
- Swift 资源库
- swift资源库--Swift泛型
- metasploit初识|资源库小记
- Swift资源库--Map方法
- swift资源库-1-变量&常量
- 初识Swift
- swift初识
- 初识swift
- Swift 初识
- 初识Swift
- 初识Swift
- 初识Swift
- 初识swift
- 初识UI
- UI初识
- Swift UI
- swift资源库——开发利器 Playground
- C#操作地图文档和图层
- Android程序的反破解技术
- MemCache工作流程
- Android仿微信界面
- Accessing the Raspberry Pi Camera with OpenCV and Python
- swift资源库-2-初识UI
- 解决java.lang.IllegalStateException: Fragment not attached to Activity
- 韩顺平Spring框架学习,学习笔记(一)
- NoSQL之Redis安装
- 杭电1209
- 科技改变了什么?
- 奋斗吧,程序员——第四十二章 会挽雕弓如满月,西北望,射天狼
- 内存对齐
- Android 微信第三方绑定登录详解