不下载你会懊悔的~~

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

  1. // UILabel
  2. var label = UILabel(frame: self.view.bounds)
  3. label.backgroundColor = UIColor.clearColor()
  4. label.textAlignment = NSTextAlignment.Center
  5. label.font = UIFont.systemFontOfSize(36)
  6. label.text = "Hello, Swift"
  7. self.view.addSubview(label)
  1. // UIButton
  2. var button = UIButton.buttonWithType(UIButtonType.System) as? UIButton
  3. button!.frame = CGRectMake(110.0, 120.0, 100.0, 50.0)
  4. button!.backgroundColor = UIColor.grayColor()
  5. button?.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)
  6. button!.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Highlighted)
  7. button?.setTitle("Touch Me", forState: UIControlState.Normal)
  8. button?.setTitle("Touch Me", forState: UIControlState.Highlighted)
  9. button?.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
  10. button!.tag = 100
  11. self.view.addSubview(button)
  1. // UIImageView
  2. var image = UIImage(named: "swift-hero.png")
  3. var imageView = UIImageView(frame: CGRectMake((CGRectGetWidth(self.view.bounds) - image.size.width) / 2.0, 120.0, image.size.width,
  4. image.size.height))
  5. imageView.image = image
  6. self.view.addSubview(imageView)
  1. // UISlider
  2. var slider = UISlider(frame:CGRectMake(60.0, 120.0, 200.0, 30.0))
  3. self.view.addSubview(slider)
  1. // UIWebView
  2. var webView = UIWebView(frame:self.view.bounds)
  3. var url = NSURL(string: "http://caipiao.m.taobao.com")
  4. var request = NSURLRequest(URL: url)
  5. webView.loadRequest(request)
  6. self.view.addSubview(webView)
  1. // UISegmentedControl
  2. var segmentControl = UISegmentedControl(items:["A", "B", "C", "D"])
  3. segmentControl.frame = CGRectMake(110.0, 120.0, 100.0, 30.0)
  4. self.view.addSubview(segmentControl)
  1. // UISwitch
  2. var switchControl = UISwitch(frame:CGRectMake(130.0, 120.0, 100.0, 30.0))
  3. switchControl.on = true
  4. self.view.addSubview(switchControl)
  1. // UITextField
  2. var textField = UITextField(frame:CGRectMake(60.0, 120.0, 200.0, 30.0))
  3. textField.backgroundColor = UIColor.lightGrayColor()
  4. textField.placeholder = "input text"
  5. self.view.addSubview(textField)
  1. // UIScrollView
  2. var scrollView = UIScrollView(frame:CGRectMake(60.0, 120.0, 200.0,
  3. 200.0))
  4. scrollView.pagingEnabled = true
  5. scrollView.showsVerticalScrollIndicator = false
  6. self.view.addSubview(scrollView)
  7. var fX: CGFloat = 0.0
  8. for(var i = 0; i < 3; ++i)
  9. {
  10. var view = UIView(frame:CGRectMake(fX, 0.0, 200.0, 200.0))
  11. fX += 200.0
  12. view.backgroundColor = UIColor.redColor()
  13. scrollView.addSubview(view)
  14. }
  15. scrollView.contentSize = CGSizeMake(3 * 200.0, 200.0)
  16. self.view.addSubview(scrollView)
  1. // UISearchBar
  2. var searchBar = UISearchBar(frame:CGRectMake(10.0, 120.0, 300.0,
  3. 30.0))
  4. searchBar.showsCancelButton = true
  5. searchBar.searchBarStyle = UISearchBarStyle.Minimal // Default, Prominent, Minimal
  6. self.view.addSubview(searchBar)
  1. // UIPageControl
  2. var pageControl = UIPageControl(frame:CGRectMake(60.0, 120.0, 200.0, 200.0))
  3. pageControl.numberOfPages = 5
  4. pageControl.currentPageIndicatorTintColor = UIColor.blackColor()
  5. pageControl.pageIndicatorTintColor = UIColor.redColor()
  6. self.view.addSubview(pageControl)
  1. // UIDatePicker
  2. var datePicker = UIDatePicker(frame:CGRectMake(0.0, 120.0, 200.0, 200.0))
  3. self.view.addSubview(datePicker)
  1. // UIPickerView
  2. var pickerView = UIPickerView(frame:CGRectMake(10.0, 120.0, 300.0, 200.0))
  3. pickerView.delegate = self
  4. pickerView.dataSource = self
  5. self.view.addSubview(pickerView)
  1. // UIProgressView
  2. var progressView = UIProgressView(progressViewStyle:UIProgressViewStyle.Default)
  3. progressView.frame = CGRectMake(10.0, 120.0, 300.0, 30.0)
  4. progressView.setProgress(0.8, animated: true)
  5. self.view.addSubview(progressView)
  1. // UITextView
  2. var textView = UITextView(frame:CGRectMake(10.0, 120.0, 300.0, 200.0))
  3. textView.backgroundColor = UIColor.lightGrayColor()
  4. textView.editable = false
  5. textView.font = UIFont.systemFontOfSize(20)
  6. 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."
  7. self.view.addSubview(textView)
  1. // UIToolbar
  2. var toolBar = UIToolbar(frame:CGRectMake(60.0, 120.0, 200.0, 30.0))
  3. var flexibleSpace = UIBarButtonItem(barButtonSystemItem:UIBarButtonSystemItem.FlexibleSpace, target:nil, action:nil)
  4. var barBtnItemA = UIBarButtonItem(title: "A", style:UIBarButtonItemStyle.Plain, target:nil, action:nil)
  5. var barBtnItemB = UIBarButtonItem(title: "B", style:UIBarButtonItemStyle.Plain, target:nil, action:nil)
  6. var barBtnItemC = UIBarButtonItem(title: "C", style:UIBarButtonItemStyle.Plain, target:nil, action:nil)
  7. var barBtnItemD = UIBarButtonItem(title: "D", style:UIBarButtonItemStyle.Plain, target:nil, action:nil)
  8. toolBar.items = [flexibleSpace, barBtnItemA, flexibleSpace, barBtnItemB, flexibleSpace, barBtnItemC, flexibleSpace, barBtnItemD, flexibleSpace]
  9. self.view.addSubview(toolBar)
  1. // UIActionSheet
  2. var alertController = UIAlertController(title: "ActionSheet", message: "Message", preferredStyle: UIAlertControllerStyle.ActionSheet)
  3. alertController.addAction(UIAlertAction(title: "Go Back", style: UIAlertActionStyle.Destructive, handler: nil))
  4. self.presentViewController(alertController, animated: true, completion:nil)
  1. // UIActivityIndicatorView
  2. var activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle:UIActivityIndicatorViewStyle.Gray)
  3. activityIndicatorView.frame = CGRectMake(140.0, 120.0, 40.0, 40.0)
  4. activityIndicatorView.startAnimating()
  5. self.view.addSubview(activityIndicatorView)
  1. // UIAlertView
  2. var alert = UIAlertController(title: "Title", message: String(format: "Result = %i", 10), preferredStyle: UIAlertControllerStyle.Alert)
  3. alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
  4. self.presentViewController(alert, animated: true, completion: nil)
  1. // UITableView
  2. var tableView : UITableView?
  3. self.tableView = UITableView(frame:self.view.frame, style:UITableViewStyle.Plain)
  4. self.tableView!.delegate = self
  5. self.tableView!.dataSource = self
  6. self.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
  7. self.view?.addSubview(self.tableView)
  8.  
  9. // UITableViewDataSource Methods
  10. func numberOfSectionsInTableView(tableView: UITableView!) -> Int
  11. {
  12. return 1
  13. }
  14. func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
  15. {
  16. return self.items!.count
  17. }
  18. func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
  19. {
  20. let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell!
  21. cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
  22. cell.textLabel.text = self.items?.objectAtIndex(indexPath.row) as String
  23.  
  24. return cell
  25. }
  26. // UITableViewDelegate Methods
  27. func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!)
  28. {
  29. self.tableView!.deselectRowAtIndexPath(indexPath, animated: true)
  30. }

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. 浅谈对JIT编译器的理解。

    1. 什么是Just In Time编译器? Hot Spot 编译 当 JVM 执行代码时,它并不立即开始编译代码.这主要有两个原因: 首先,如果这段代码本身在将来只会被执行一次,那么从本质上看,编 ...

  2. Kerberos-KDC

    Kerberos提供一种较好的解决方案,它是由MIT发明的,Kerberos建立了一个安全的.可信任的密钥分发中心(KDC, Key Distribution Center).Kerberos是一种认 ...

  3. oracle(天猫处方药留言sql)

    " ?> .dtd" > <sqlMap namespace="TmallTcMessage"> <typeAlias alias ...

  4. oracle之replace结合substr的使用

    select * from( SELECT TMM.ORDER_ID, TMM.IMPORT_ID, TMM.TMALL_ORDER_ID, TMM.MEMBER_NAME, TMM.ALIPAY_U ...

  5. SQL SERVER数据库服务操作

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. word-wrap 和 word-break

    一.word-wrap 1.浏览器支持 所有主流浏览器都支持 word-wrap属性 2.定义和用法 word-wrap 属性允许长单词或 URL 地址换行到下一行. 语法 word-wrap: no ...

  7. win8 安装myeclipse 失败 MyEclipse ForSpring 安装失败

    好像是main方法.jar无法载入之类的.. 可能是权限的问题哦.. 使用管理员权限试一下..

  8. 连接Oracle11g数据库时遇到无监听,网络适配器无法建立等问题的一些解决办法

    最近在用Java做一个学生成绩管理系统,打算用Oracle数据库.由于原先没接触过Oracle,所以安装完数据库后,连接数据库时遇到各种问题,网上搜索解决方案还是没有解决时,又重新安装了几次.终于在前 ...

  9. iOS中发送xml给服务器

    转载自:http://www.cocoachina.com/bbs/read.php?tid-456019.html 一.用URLSession请求 NSString *soapStr = [NSSt ...

  10. 关于extern对变量的使用

    extern 是声明全局的变量的意思. 例如在一个工程中有两个cpp,一个是test.cpp一个是main.cpp . 我们在test.cpp中定义了一个int num;但是我们在main.cpp中想 ...