不下载你会懊悔的~~

下载地址:https://github.com/HunkSmile/Swift.git

// UILabel
var label = UILabel(frame: self.view.bounds)
label.backgroundColor = UIColor.clearColor()
label.textAlignment = NSTextAlignment.Center
label.font = UIFont.systemFontOfSize(36)
label.text = "Hello, Swift"
self.view.addSubview(label)
// UIButton
var button = UIButton.buttonWithType(UIButtonType.System) as? UIButton
button!.frame = CGRectMake(110.0, 120.0, 100.0, 50.0)
button!.backgroundColor = UIColor.grayColor()
button?.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)
button!.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Highlighted)
button?.setTitle("Touch Me", forState: UIControlState.Normal)
button?.setTitle("Touch Me", forState: UIControlState.Highlighted)
button?.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
button!.tag = 100
self.view.addSubview(button)
// UIImageView
var image = UIImage(named: "swift-hero.png")
var imageView = UIImageView(frame: CGRectMake((CGRectGetWidth(self.view.bounds) - image.size.width) / 2.0, 120.0, image.size.width,
image.size.height))
imageView.image = image
self.view.addSubview(imageView)
// UISlider
var slider = UISlider(frame:CGRectMake(60.0, 120.0, 200.0, 30.0))
self.view.addSubview(slider)
// UIWebView
var webView = UIWebView(frame:self.view.bounds)
var url = NSURL(string: "http://caipiao.m.taobao.com")
var request = NSURLRequest(URL: url)
webView.loadRequest(request)
self.view.addSubview(webView)
// UISegmentedControl
var segmentControl = UISegmentedControl(items:["A", "B", "C", "D"])
segmentControl.frame = CGRectMake(110.0, 120.0, 100.0, 30.0)
self.view.addSubview(segmentControl)
// UISwitch
var switchControl = UISwitch(frame:CGRectMake(130.0, 120.0, 100.0, 30.0))
switchControl.on = true
self.view.addSubview(switchControl)
// UITextField
var textField = UITextField(frame:CGRectMake(60.0, 120.0, 200.0, 30.0))
textField.backgroundColor = UIColor.lightGrayColor()
textField.placeholder = "input text"
self.view.addSubview(textField)
// UIScrollView
var scrollView = UIScrollView(frame:CGRectMake(60.0, 120.0, 200.0,
200.0))
scrollView.pagingEnabled = true
scrollView.showsVerticalScrollIndicator = false
self.view.addSubview(scrollView)
var fX: CGFloat = 0.0
for(var i = 0; i < 3; ++i)
{
var view = UIView(frame:CGRectMake(fX, 0.0, 200.0, 200.0))
fX += 200.0
view.backgroundColor = UIColor.redColor()
scrollView.addSubview(view)
}
scrollView.contentSize = CGSizeMake(3 * 200.0, 200.0)
self.view.addSubview(scrollView)
// UISearchBar
var searchBar = UISearchBar(frame:CGRectMake(10.0, 120.0, 300.0,
30.0))
searchBar.showsCancelButton = true
searchBar.searchBarStyle = UISearchBarStyle.Minimal // Default, Prominent, Minimal
self.view.addSubview(searchBar)
// UIPageControl
var pageControl = UIPageControl(frame:CGRectMake(60.0, 120.0, 200.0, 200.0))
pageControl.numberOfPages = 5
pageControl.currentPageIndicatorTintColor = UIColor.blackColor()
pageControl.pageIndicatorTintColor = UIColor.redColor()
self.view.addSubview(pageControl)
// UIDatePicker
var datePicker = UIDatePicker(frame:CGRectMake(0.0, 120.0, 200.0, 200.0))
self.view.addSubview(datePicker)
// UIPickerView
var pickerView = UIPickerView(frame:CGRectMake(10.0, 120.0, 300.0, 200.0))
pickerView.delegate = self
pickerView.dataSource = self
self.view.addSubview(pickerView)
// UIProgressView
var progressView = UIProgressView(progressViewStyle:UIProgressViewStyle.Default)
progressView.frame = CGRectMake(10.0, 120.0, 300.0, 30.0)
progressView.setProgress(0.8, animated: true)
self.view.addSubview(progressView)
// UITextView
var textView = UITextView(frame:CGRectMake(10.0, 120.0, 300.0, 200.0))
textView.backgroundColor = UIColor.lightGrayColor()
textView.editable = false
textView.font = UIFont.systemFontOfSize(20)
textView.text = "Swift is an innovative new programming language for Cocoa and Cocoa Touch. Writing code is interactive and fun, the syntax is concise yet expressive, and apps run lightning-fast. Swift is ready for your next iOS and OS X project — or for addition into your current app — because Swift code works side-by-side with Objective-C."
self.view.addSubview(textView)
// UIToolbar
var toolBar = UIToolbar(frame:CGRectMake(60.0, 120.0, 200.0, 30.0))
var flexibleSpace = UIBarButtonItem(barButtonSystemItem:UIBarButtonSystemItem.FlexibleSpace, target:nil, action:nil)
var barBtnItemA = UIBarButtonItem(title: "A", style:UIBarButtonItemStyle.Plain, target:nil, action:nil)
var barBtnItemB = UIBarButtonItem(title: "B", style:UIBarButtonItemStyle.Plain, target:nil, action:nil)
var barBtnItemC = UIBarButtonItem(title: "C", style:UIBarButtonItemStyle.Plain, target:nil, action:nil)
var barBtnItemD = UIBarButtonItem(title: "D", style:UIBarButtonItemStyle.Plain, target:nil, action:nil)
toolBar.items = [flexibleSpace, barBtnItemA, flexibleSpace, barBtnItemB, flexibleSpace, barBtnItemC, flexibleSpace, barBtnItemD, flexibleSpace]
self.view.addSubview(toolBar)
// UIActionSheet
var alertController = UIAlertController(title: "ActionSheet", message: "Message", preferredStyle: UIAlertControllerStyle.ActionSheet)
alertController.addAction(UIAlertAction(title: "Go Back", style: UIAlertActionStyle.Destructive, handler: nil))
self.presentViewController(alertController, animated: true, completion:nil)
// UIActivityIndicatorView
var activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle:UIActivityIndicatorViewStyle.Gray)
activityIndicatorView.frame = CGRectMake(140.0, 120.0, 40.0, 40.0)
activityIndicatorView.startAnimating()
self.view.addSubview(activityIndicatorView)
// UIAlertView
var alert = UIAlertController(title: "Title", message: String(format: "Result = %i", 10), preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
// UITableView
var tableView : UITableView?
self.tableView = UITableView(frame:self.view.frame, style:UITableViewStyle.Plain)
self.tableView!.delegate = self
self.tableView!.dataSource = self
self.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
self.view?.addSubview(self.tableView) // UITableViewDataSource Methods
func numberOfSectionsInTableView(tableView: UITableView!) -> Int
{
return 1
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
{
return self.items!.count
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell!
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
cell.textLabel.text = self.items?.objectAtIndex(indexPath.row) as String return cell
}
// UITableViewDelegate Methods
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!)
{
self.tableView!.deselectRowAtIndexPath(indexPath, animated: true)
}

Apple Swfit UI控件实现的更多相关文章

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

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

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

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

  3. ANDROID L——Material Design详解(UI控件)

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...

  4. WinForm/Silverlight多线程编程中如何更新UI控件的值

    单线程的winfom程序中,设置一个控件的值是很easy的事情,直接 this.TextBox1.value = "Hello World!";就搞定了,但是如果在一个新线程中这么 ...

  5. 富客户端 wpf, Winform 多线程更新UI控件

    前言 在富客户端的app中,如果在主线程中运行一些长时间的任务,那么应用程序的UI就不能正常相应.因为主线程要负责消息循环,相应鼠标等事件还有展现UI. 因此我们可以开启一个线程来格外处理需要长时间的 ...

  6. UI控件(复习一下)

    如何修改控件状态• 可见,确实需要经常修改控件状态• 那如何去修改控件的状态呢?方法很简单➢ 每一个UI控件都是一个对象➢ 修改UI控件的状态,其实就是修改控件对象的属性➢ 比如修改UILabel显示 ...

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

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

  8. 《深入理解Windows Phone 8.1 UI控件编程》基于最新的Runtime框架

    <深入理解Windows Phone 8.1 UI控件编程>本书基于最新的Windows Phone 8.1 Runtime SDK编写,全面深入地论述了最酷的UI编程技术:实现复杂炫酷的 ...

  9. (转).NET 4.5中使用Task.Run和Parallel.For()实现的C# Winform多线程任务及跨线程更新UI控件综合实例

    http://2sharings.com/2014/net-4-5-task-run-parallel-for-winform-cross-multiple-threads-update-ui-dem ...

随机推荐

  1. gcc/g++/make 编译信息带颜色输出

    假设编译一个项目错误警告太多.很不好找,所以很希望输出信息能够带有颜色. 但是 gcc 4.9.0 之前的版本号并不支持,非常多情况下是不能替换编译器的,比方使用交叉编译器, 也能够使用 colorg ...

  2. const与define的异同

    1. DEFINE是预处理指令,是简单的文字替换:而const是关键字,用于变量声明的修饰. 2. DEFINE替换的结果可以是数值.表达式.字符串.甚至是一个程序:而const只能限定变量为不可修改 ...

  3. <经验杂谈>C#/.Net中xml的Serialization序列化与DeSerializetion反序列化

    1.先讲概念:.Net Framework提供了对应的System.Xml.Seriazliation.XmlSerializer负责把对象序列化到XML,和从XML中反序列化为对象.Serializ ...

  4. Javascript基础Function

    函数声明与表达式 function someFunc(){ alert("这是一个函数"); } var func=function(){ alert("函数表达式&qu ...

  5. 一致性哈希与java实现

    一致性哈希算法是分布式系统中常用的算法.比如,一个分布式的存储系统,要将数据存储到具体的节点上,如果采用普通的hash方法,将数据映射到具体的节点上,如key%N,key是数据的key,N是机器节点数 ...

  6. Private Members in JavaScript

    Private Members in JavaScript Douglas Crockford www.crockford.com JavaScript is the world's most mis ...

  7. C#三个平台上的文件选择方法

    wpf: Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = &qu ...

  8. PHP获取文件后缀名的三种方法

    如下: <? PHP获取文件后缀名的几种方法1: function get_file_type($filename){ $type = substr($filename, strrpos($fi ...

  9. myeclipse 不能添加非myeclipse开发的项目

    这是因为以前的项目不是用myEclipse创建的,所以用myeclipse deploy的时候找不到你的项目.可以这样做:右击原项目名 - myeclipse - Add Web Project Ca ...

  10. Bootstrap定制(二)less基础语法

    前几日花了一天去看less,这几日在捣鼓其他东西,项目也在有序的进行中,今天花点时间整理下less的基础语法,也分享实际中的一些经验,与众人共享. 本篇笔者以less的基础语法着手,并配合bootst ...