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 ...
随机推荐
- Redhat7.2 如何修改主机名(hostname)?
Redhat7.2 在安装的时候,会默认生成主机名:localhost. 那么如何修改成自己想要的自己名? //格式为:用户名@主机名 比如: [root@localhost ~]# 修改成[roo ...
- linux的计划
我接触linux也有好几年了,至少有5年了.最近公司在搞内部培训,人人都可以报名培训别人.想到自己在linux浸淫多年,应该出来出一份力.一直以来想就linux写一个专题.今天刚好在做相关的ppt,借 ...
- 手机端布局 - rem计算
功能说明:以一个640px的宽度为基准,最小不低于320px,当大于640px时,让其在页面中居中. 如果正处于640 - 320之中的,都按照js进行等比例的缩放. 这里我们规定1rem = 100 ...
- UEditor的使用
一.引用CSS和JS: <meta http-equiv="Content-Type" content="text/html;charset=utf-8" ...
- NetworkError: 404 Not Found - http://www.companyName.com/Content/fonts/ubuntu-regular-webfont.woff2
网站是使用BootStrap框架实现,当站点发布至服务器(Windows Server 2008 R2)IIS之后,显示下面的异常: Insus.NET跑至相关目录之下检查,这些字体的文件是确实存在的 ...
- 基于MVC4+EasyUI的Web开发框架经验总结(8)--实现Office文档的预览
在博客园很多文章里面,曾经有一些介绍Office文档预览查看操作的,有些通过转为PDF进行查看,有些通过把它转换为Flash进行查看,但是过程都是曲线救国,真正能够简洁方便的实现Office文档的预览 ...
- WinForm 容器控件
容器控件: 布局:2个属性:Anchor:锁定位置Dock:填充位置一般Dock是与容器控件配合使用 Panel:就是一个区域,类似于DIV,可以独立布局,还可以让其它控件及容器在它的内部再次布局 F ...
- C#的变迁史 - C# 5.0 之调用信息增强篇
Caller Information CallerInformation是一个简单的新特性,包括三个新引入的Attribute,使用它们可以用来获取方法调用者的信息, 这三个Attribute在Sys ...
- UVA 253 Cube painting
大致题意:有三种颜色,一个立方体6面都可以涂一种颜色.现在给出两个每个面都涂好颜色的立方体,判断这两个立方体通过旋转是否相等. 立方体的旋转出来的结果有很多,首先可以0,1,2,3,4,5(顺序是:上 ...
- ubuntu 下安装memcache 以及php扩展
1,下载软件 下载 memcached http://memcached.org/downloads 下载libevent http://libevent.org/ 2,安装 ...