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("不帅!!!!")
}
}
}
swift学习之UI控件(一)的更多相关文章
- 用swift创建各种UI控件【iSwifting社区】
为了方便大家学习,www.iSwifting.com社区为大家准备了创建各种UI控件的代码.開始看着语法可能有些别扭,当用习惯了,就认为还是非常不错的. 社区还添加了问答专区.有问题的朋友.虽然问.大 ...
- Swift学习之熟悉控件
最近是比较清闲一些的,对于一个开发者来说,这也是一个很好的充电机会.以前做项目都是使用Objective-C去开发,但我们都知道,Swift语言从2014年的出现到现在,一步一步变的完善,渐渐变的受欢 ...
- 安卓学习之--UI控件用法 单选 按钮 下拉框
1.单选 .RadioGroup 可将各自不同的RadioButton ,设限于同一个Radio 按钮组,同一个RadioGroup 组里的按钮,只能做出单一选择(单选题). <RadioGro ...
- Android学习路-UI控件
- Swift UI控件详细介绍(上)
UI控件 首先介绍一下AppDelegate.swift@UIApplicationMain 调用了OC中的UIApplicationMain函数:UIApplicationMain是iOS应用程序的 ...
- iOS基础UI控件介绍-Swift版
iOS基础UI控件总结 iOS基础控件包括以下几类: 1.继承自NSObject:(暂列为控件) UIColor //颜色 UIImage //图像 2.继承自UIView: 只能相应手势UIGest ...
- IOS学习资源收集--开发UI控件相关
收集的一些本人了解过的iOS开发UI控件相关的代码资源(本文持续补充更新) 内容大纲: 1.本人在github上也上传了我分装好的一些可重复利用的UI控件 2.计时相关的自定义UILabel控件 正文 ...
- AppleWatch___学习笔记(二)UI布局和UI控件
1.UI布局 直接开发,你会发现Apple Watch并不支持AutoLayout,WatchKit里有个类叫做WKInterfaceGroup,乍一看像是UIView,但是这货其实是用来布局的.从 ...
- ios 中的UI控件学习总结(1)
UIKit框架提供了非常多功能强大又易用的UI控件 下面列举一些在开发中可能用得上的UI控件 UIButton 按钮 UILabel 文本标签 UITextField 文本输入框 UIImageVie ...
随机推荐
- C#--静态函数成员
- 瀑布式开发、迭代开发、敏捷开发、XP与SCRUM的区别
瀑布式开发.迭代开发,区别[都属于,生命周期模型] 两者都是一种开发模式,就像设计模式一样,考虑的角度不一样,个人感觉谈不到取代一说. 传统的瀑布式开发,也就是从需求到 ...
- C#连接Excel示例代码和驱动
代码如下: string fileExt = Path.GetExtension(excelPath); string conn = ""; if (fileExt == &quo ...
- 关于js性能
1,声明变量要赋初值2,尽量避免声明全局变量,可以减少与系统的重名3,当编写大量js代码时,难免会遇到命名冲突,这是可以通过模拟命名空间方式 来避免冲突4,尽量避免使用全局变量,搜索全局变量是 ...
- C#调用Java方法(详细实例)
C#可以直接引用C++的DLL和转换JAVA写好的程序.最近由于工作原因接触这方面比较多,根据实际需求,我们通过一个具体例子把一个JAVA方法转换成可以由C#直接调用的DLL C#调用c++ C#调用 ...
- 【C#】使用IExtenderProvider为控件添加扩展属性,像ToolTip那样
申明: - 本文适用于WinForm开发 - 文中的“控件”一词是广义上的说法,泛指包括ToolStripItem.MenuItem在内单个界面元素,并不特指继承自Control类的狭义控件 用过To ...
- iOS阶段学习第16天笔记(Category-NSSet-SEL-NSIndexSet 操作)
iOS学习(OC语言)知识点整理 一.NSSet.NSMutableSet集合的介绍 1)NSSet.NSMutableSet集合,元素是无序的,不能有重复的值. 2)用实例方法创建一个不可变集合对象 ...
- Mysql高并发优化
一.数据库结构的设计 1.数据行的长度不要超过8020字节,如果超过这个长度的话在物理页中这条数据会占用两行从而造成存储碎片,降低查询效率. 2.能够用数字类型的字段尽量选择数字类型而不用字符串类型的 ...
- MFC 阶段学习总结
由于项目需求,需要用到C++开发软件,所以开始学习C++,重点是MFC,因为是窗体应用,感觉win32的比较麻烦,还是MFC方便点.至于为什么要用C++呢, 由于C++应用不需要客户额外安装环境和加密 ...
- form表单
<form> <input type="text" value="123"> 文本输入框,value值为显示在文本框中的默认值, ...