swift学习之UI空间(一)

//

//  ViewController.swift

//  test

//

//  Created by chuangqu on 15/7/23.

//  Copyright (c) 2015年 theway. All rights reserved.

//

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

var lable = UILabel(frame: CGRectMake(120, 20, 100, 20))

lable.text = "小猪飞!"

lable.textColor = UIColor.blueColor()

lable.backgroundColor = UIColor.brownColor()

lable.textAlignment = NSTextAlignment.Center

lable.shadowColor = UIColor.grayColor()

lable.shadowOffset = CGSizeMake(-5, 5)

lable.font = UIFont(name: "zapfino", size: 20)

self.view.addSubview(lable)

var file = UITextField(frame: CGRectMake(120, 80, 100, 20))

file.text = "肖"

file.textColor = UIColor.blueColor()

self.view.addSubview(file)

var button:UIButton = UIButton.buttonWithType(UIButtonType.System)as!UIButton;

button.frame = CGRectMake(120, 150, 100, 80)

button.setTitle("猪fjygjyy", forState:UIControlState.Normal)

//        button.setImage(UIImage(named: "0"), forState: .Normal)

button.adjustsImageWhenHighlighted = false

button.setBackgroundImage(UIImage(named: "0"), forState: .Normal)//设置背景

button.addTarget(self, action: Selector("test"), forControlEvents: UIControlEvents.TouchUpInside)

self.view.addSubview(button)

segmented ()

/*

创建一个文本框

*/

var textfield = UITextField(frame: CGRectMake(10, 20, 100, 20))

textfield.borderStyle = UITextBorderStyle.RoundedRect//设置文本框为圆边圆角

textfield.placeholder = "yuebu"//设置提示语句

//        textfield.text = "hhhh"//设置默认值

textfield.adjustsFontSizeToFitWidth = true //设置当超出文本时文字省略方式

//        textfield.textAlignment = NSTextAlignment.Center//设置文字的水平对齐属性

//        textfield.contentVerticalAlignment = UIControlContentVerticalAlignment.Center//垂直对齐方式

//简写

//        textfield.returnKeyType = UIReturnKeyType.Go//设置键盘的返回键作用

textfield.contentVerticalAlignment = .Center

textfield.clearButtonMode = .WhileEditing

//        textfield.clearButtonMode = UITextFieldViewMode.UnlessEditing

//        textfield.clearButtonMode = .UnlessEditing

self.view.addSubview(textfield)

//        kaiguan()

img ()

animation ()

//         progess()

//        test()

// Do any additional setup after loading the view, typically from a nib.

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

func test() {

//        button.setTitle("小大", forState: UIControlState.Normal)//不能改变UI,需在UI线程中操作

println("我肾很好!")

}

func kaiguan (){

var uiswitch : UISwitch

uiswitch = UISwitch()

uiswitch.center = CGPointMake(100, 50)

uiswitch.on = true

self.view.addSubview(uiswitch)

}

func segmented (){

var items = ["张","萧","阿","姨"]//,UIImage(named: "icon")]

var seg = UISegmentedControl(items: items)

seg.center = self.view.center

seg.selectedSegmentIndex = 1

self.view.addSubview(seg)

}

func img (){

var imge = UIImageView(image: UIImage(named: "3"))

imge.frame = CGRectMake(90,350, 200, 200)

self.view.addSubview(imge)

}

var imageview : UIImageView!

func animation (){

imageview = UIImageView()

imageview.frame = CGRectMake(90,350, 200, 200)

//帧动画设置

//        imageview.animationImages = [UIImage(named:"0"),UIImage(named:"3")]

//设置变化时间

imageview.animationDuration = 0.5

self.view.addSubview(imageview)

}

override func viewWillAppear(animated: Bool) {

super.viewWillAppear(animated)

imageview.startAnimating()

}

override func viewWillDisappear(animated: Bool) {

super.viewWillDisappear(animated)

imageview.stopAnimating()

}

//    override func DidLoad() {

//        super.viewDidLoad()

//        imageview = UIImageView()

//        imageview.frame = CGRectMake(90,350, 200, 200)

//        //帧动画设置

//        imageview.animationImages = [UIImage(named: "3"),UIImage(named: "3"),UIImage(named: "3")]

//        //设置变化时间

//        imageview.animationDuration = 0.5

//        self.view.addSubview(imageview)

//

//    }

func progess(){

var progres = UIProgressView(progressViewStyle: UIProgressViewStyle.Default)

progres.center = self.view.center

progres.progress = 0.5

progres.setProgress(0.8, animated: true)

self.view.addSubview(progres)

var alert = UIAlertView()

alert.frame = CGRectMake(200, 150, 100, 100)

alert.title = "刘大神帅不"

alert.message = "是/否"

alert.addButtonWithTitle("是")

alert.addButtonWithTitle("否")

alert.cancelButtonIndex = 0

alert.delegate = self

alert.show()

hhh(alert, clickedButtonAlertIndex: alert.cancelButtonIndex)

}

func hhh(alert:UIAlertView,clickedButtonAlertIndex button:Int){

if button == alert.cancelButtonIndex {

print("不帅")

}

else{

print("不帅!!!!")

}

}

}

时间: 2024-08-06 07:28:08

swift学习之UI空间(一)的相关文章

Swift学习之常用UI的使用

Swift学习之常用UI的使用 最近笔者在开始学习苹果最新的编程语言,因为笔者认为,苹果既然出了这门语言就绝对不会放弃,除非苹果倒闭了(当然这里知识一个玩笑). 所以在不久的将来,swift绝对是iOS 开发的主导语言,也许不会完全取代OC. 笔者学完swift的语法之后就开始着手UI了,因为我觉得有着一定的OC基础.所以这里关于swift的语法就不做多介绍了,在后面的文章中,我将会详细介绍一下关于swift中的重点,难点语法和一些新特性. 下面是我在学习UI的时候自己总结的一些swift创建U

汇集了很多swift 学习指南

https://github.com/ipader/SwiftGuide 1,059   Unstar7,294 Fork1,966 ipader/SwiftGuide CodeIssues 0Pull requests 0WikiPulseGraphs 这份指南汇集了Swift语言主流学习资源,并以开发者的视角整理编排.http://dev.swiftguide.cn 376 commits 3 branches 0 releases 12 contributors Swift 100.0%

swift学习笔记(七)自动引用计数

与Object-c一样,swift使用自动引用计数来跟踪并管理应用使用的内存.当实例不再被使用时,及retainCount=0时,会自动释放是理所占用的内存空间. 注:引用计数仅适用于类的实例,因为struct和enumeration属于值类型,也就不牵涉引用,所以其存储和管理方式并不是引用计数. 当一个实例被初始化时,系统会自动分配一定的内存空间,用于管理属性和方法.当实例对象不再被使用时,其内存空间被收回. swift中的引用类型分为三种,即Strong强引用,weak弱引用和无主引用unw

Swift学习笔记:类和结构

一.类和结构的异同 类和结构有一些相似的地方,它们都可以: 1. 定义一些可以赋值的属性: 2. 定义具有功能性的方法 3. 定义下标,使用下标语法 4. 定义初始化方法来设置初始状态 5. 在原实现方法上的可扩展性 根据协议提供某一特定类别的基本功能 1. 类还有一些结构不具备的特性: 2. 类的继承性 3. 对类实例实时的类型转换 4. 析构一个类的实例使之释放空间 5. 引用计数,一个类实例可以有多个引用 1. 定义语法 struct Name{ let firstName = "&quo

iOS ---Swift学习与复习

swift中文网 http://www.swiftv.cn http://swifter.tips/ http://objccn.io/ http://www.swiftmi.com/code4swift http://stackoverflow.com http://weibo.com/oldcoder 43个优秀的Swift开源项目推荐 https://developer.apple.com/swift/blog/ http://code.cocoachina.com http://swif

Swift 学习指南

github地址:https://github.com/ipader/SwiftGuide Swift 语言指南 @SwiftLanguage 更新于 2016-4-18,更新内容详见 Issue 51.往期更新回顾详见<收录周报> 这份指南汇集了 Swift 语言主流学习资源,并以开发者的视角整理编排.对于精选项目及文章,可直接访问<Swift 项目精选>和<Swift 文章精选>. 目录 入门指引 教程文章 开源项目 推荐网站 开发工具 媒体报道 开放平台 Appl

12套swift学习资源分享

虽然objective-c编程语言在过去很长一段时间都是iOS应用开发的基础语言,且很多iOS开发者对其也深爱有佳,但是随着swift编程语言的问世,迅速发展为开发者追捧的语言.且今年伴随着swift2.0的问世及swift语言的开源,更加奠定了其在今后的发展. 接触过swift语言的童鞋应该都知道,在开发 OS X, IOS, watchOS 和 TVOS 应用上,Swift 毫无疑问就是未来.它结合了 C 和 Objective-C 的众多优点,而且支持 Cocoa 和 Cocoa Touc

Swift学习笔记(11)--类与结构体

类与结构是编程人员在代码中会经常用到的代码块.在类与结构中可以像定义常量,变量和函数一样,定义相关的属性和方法以此来实现各种功能. 和其它的编程语言不太相同的是,Swift不需要单独创建接口或者实现文件来使用类或者结构.Swift中的类或者结构可以在单文件中直接定义,一旦定义完成后,就能够被直接其它代码使用. 注意:一个类的实例一般被视作一个对象,但是在Swift中,类与结构更像是一个函数方法,在后续的章节中更多地是讲述类和结构的功能性. 1.类和结构的异同 类和结构有一些相似的地方,它们都可以

【转载】OpenStack Swift学习笔记

免责声明:     本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除.     原文作者:崔炳华      原文地址:http://blog.csdn.net/i_chips/article/details/17787017 1       概述 OpenStack Object Storage(Swift)是OpenStack开源云计算项目的子项目之一.Swift的目的是使用普通硬件来构建冗余的.可扩展的分布式对象存储集群,存储容量可达PB级. Swift并不是