//

//  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("不帅!!!!")

}

}

}

swift学习之UI控件(一)的更多相关文章

  1. 用swift创建各种UI控件【iSwifting社区】

    为了方便大家学习,www.iSwifting.com社区为大家准备了创建各种UI控件的代码.開始看着语法可能有些别扭,当用习惯了,就认为还是非常不错的. 社区还添加了问答专区.有问题的朋友.虽然问.大 ...

  2. Swift学习之熟悉控件

    最近是比较清闲一些的,对于一个开发者来说,这也是一个很好的充电机会.以前做项目都是使用Objective-C去开发,但我们都知道,Swift语言从2014年的出现到现在,一步一步变的完善,渐渐变的受欢 ...

  3. 安卓学习之--UI控件用法 单选 按钮 下拉框

    1.单选 .RadioGroup 可将各自不同的RadioButton ,设限于同一个Radio 按钮组,同一个RadioGroup 组里的按钮,只能做出单一选择(单选题). <RadioGro ...

  4. Android学习路-UI控件

  5. Swift UI控件详细介绍(上)

    UI控件 首先介绍一下AppDelegate.swift@UIApplicationMain 调用了OC中的UIApplicationMain函数:UIApplicationMain是iOS应用程序的 ...

  6. iOS基础UI控件介绍-Swift版

    iOS基础UI控件总结 iOS基础控件包括以下几类: 1.继承自NSObject:(暂列为控件) UIColor //颜色 UIImage //图像 2.继承自UIView: 只能相应手势UIGest ...

  7. IOS学习资源收集--开发UI控件相关

    收集的一些本人了解过的iOS开发UI控件相关的代码资源(本文持续补充更新) 内容大纲: 1.本人在github上也上传了我分装好的一些可重复利用的UI控件 2.计时相关的自定义UILabel控件 正文 ...

  8. AppleWatch___学习笔记(二)UI布局和UI控件

    1.UI布局 直接开发,你会发现Apple Watch并不支持AutoLayout,WatchKit里有个类叫做WKInterfaceGroup,乍一看像是UIView,但是这货其实是用来布局的.从 ...

  9. ios 中的UI控件学习总结(1)

    UIKit框架提供了非常多功能强大又易用的UI控件 下面列举一些在开发中可能用得上的UI控件 UIButton 按钮 UILabel 文本标签 UITextField 文本输入框 UIImageVie ...

随机推荐

  1. 开源服务专题之-------rsync数据备份

    RSYNC是Remote Sync 远程同步的简称,与SCP的比较,SCP= 无法备份大量数据,类似windows的复制,而rsync=边复制 ,边统计,边比较,可以备份大量数据.可以镜像保存整个目录 ...

  2. Android Studio快捷键每日一练(4)

    原文地址:http://www.developerphil.com/android-studio-tips-of-the-day-roundup-4/ 33.分析数据流到当前位置 苹果/Windows ...

  3. js正则中的贪婪和非贪婪模式问题总结

    var b="abeeee:eeeee:eeeeeab"; console.log(b.match(/e+\:e+/g));//["eeee:eeeee"]贪婪 ...

  4. 九个Console命令,让js调试更简单

    一.显示信息的命令 最常用的就是console.log了. 二.占位符 console上述的集中度支持printf的占位符格式,支持的占位符有:字符(%s).整数(%d或%i).浮点数(%f)和对象( ...

  5. 【SQL】靠谱的TRIM函数,附赠过程一枚

    SQL中有LTRIM和RTRIM这两个函数分别用于去除字符串的首.尾空格,缺乏常见的能同时去除首尾的TRIM函数,另外,这俩函数都只对[空格]有效,所以如果首尾是制表符.换行符等等[空白],它们是不处 ...

  6. CPU介绍

    CPU内核主要分为两部分:运算器和控制器. (一) 运算器 cpu基本想到的是计算,因此有算数计算,还有逻辑计算单元以及移位简单的运算:fp运算单独拿出:要运算就需要输入数字,因此有寄存器组,即通用寄 ...

  7. Nancy 自定义JsonSerializer

    1.创建自己的jsonserializer类 public class CustomJsonNetSerializer : JsonSerializer, ISerializer { public C ...

  8. spring笔记2 spring MVC的基础知识2

    2,spring MVC的注解驱动控制器,rest风格的支持 作为spring mvc的明星级别的功能,无疑是使得自己的code比较优雅的秘密武器: @RequestMapping处理用户的请求,下面 ...

  9. TabHost的使用

    Android中的选项卡是用TabHost实现的. 首先,定义TabHost的布局文件: <?xml version="1.0" encoding="utf-8&q ...

  10. hibernate3

    hibernate3 (整合到spring中的core核心配置中的hibernate3) <!-- 基于hibernate的Session工厂 --> <bean id=" ...