- 博客(36)
- 收藏
- 关注
原创 36. Quartz 2D之渐变和裁剪
Quartz 2D之渐变和裁剪渐变分为两种: 线性渐变和径向渐变, 我们将学习使用它:1. 线性渐变// MARK: - 绘制渐变// MARK: 线性渐变func drawGradient(context: CGContextRef?) { // 1. 绘制渐变 // 创建渐变 let components: [CGFloat] = [1.0, 0.0, 0.0, 1.0
2016-03-27 21:25:30
598
原创 35. Quartz 2D初探
Quartz 2D初探Quartz 2D支持iOS和Mac OS X的2D图形绘制引擎.我们将学习用它来绘制 线条/矩形/圆形/圆弧/文字/图像1. 自定义UIView自定义UIView的步骤:自定义一个类继承UIView重写init如果要自定义绘制的话, 实现drawRect方法import UIKitclass MyView: UIView { override init(fram
2016-03-25 21:56:31
423
原创 34. 多线程之NSOperation和NSOperationQueue
NSOperationNSOperation是GCD面向对象的封装, 它有更多的特性.文档中说NSOperation是一个抽象类, 不要直接使用它,使用它的子类或定义一个继承它的类.它的子类有 NSInvocationOperation 和NSBlockOperation, 貌似swift中没有NSInvocationOperation类, 我们就只管NSBlockOperation了.1. NSB
2016-03-19 16:43:12
424
原创 33.多线程之GCD
GCDGCD即Grand Central Dispatch, 是苹果推荐使用的多线程技术, 它可以充分利用多核.它通过队列来安排任务, GCD队列分为三种:全局队列主队列串行队列下面我们学习它们1. 全局队列全局队列是一个并发队列. 我们来创建一个全局队列:let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAUL
2016-03-19 12:00:43
468
原创 32. 自定义UITableViewCell(高度自适应)
自定义UITableViewCell自定义一个UITableViewCell, 需要定义一个类,继承UITableViewCell即可,而实现高度自适应,只需要设置UITableView的两个属性即可:// 预估行高self.tableView.estimatedRowHeight = 100// 行高自动测量self.tableView.rowHeight = UITableViewAuto
2016-03-19 00:31:20
918
原创 31. UITableView的编辑模式
UITableView的编辑模式通过前面的几节,我们对UITableView应该有所了解了, 下面我们学习如何使用编辑模式:1. 实现多选删除import UIKitclass ViewController2: UIViewController, UITableViewDelegate, UITableViewDataSource { var tableView: UITableView!
2016-03-16 15:45:01
442
原创 30. UITableViewDelegate详解
UITableViewDelegate它用于表现cell的显示和行为,我们查看它的定义:public protocol UITableViewDelegate : NSObjectProtocol, UIScrollViewDelegate { // 自定义显示 // cell将要显示时回调 @available(iOS 2.0, *) optional public f
2016-03-16 12:46:38
3393
原创 29.UITableViewDataSource详解
UITableViewDataSource这节我们介绍UITableViewDataSource, 它用于定义tableView的显示.下面我们查看它的定义:public protocol UITableViewDataSource : NSObjectProtocol { // 设置行数 @available(iOS 2.0, *) public func tableView
2016-03-15 23:41:04
781
原创 28.UITableView类详解
UITableView类详解这个小结我们学习UITable的属性和方法, 粗略的翻一翻就行了, 遇到不懂的再回来查看.我们查看它的定义:@available(iOS 2.0, *)public class UITableView : UIScrollView, NSCoding { public init(frame: CGRect, style: UITableViewStyle)
2016-03-15 22:27:40
480
原创 27.UITableView初探
UITableViewUITableView是iOS中使用非常常用的控件,它是一个列表控件, 下面我们学习如何使用它1. UITableView的创建import UIKitclass ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { override func viewDidLoad(
2016-03-13 21:24:52
411
原创 26.手势识别之UILongPressGestureRecognizer
UILongPressGestureRecognizer长按手势, 它的使用和其它手势没什么区别,我们将学习如何使用它1. UILongPressGestureRecognizer的创建import UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidL
2016-03-11 20:28:11
533
原创 25.手势识别之UIScreenEdgePanGestureRecognizer
UIScreenEdgePanGestureRecognizer它是UIPanGestureRecognizer的子类, 必须从设置的边缘开发拖动才能触发这个手势, 下面我们学习如何使用它1. UIScreenEdgePanGestureRecognizer创建我们使用上一节的例子, 图片随手指移动:import UIKitclass ViewController19: UIViewControll
2016-03-11 17:54:39
1732
原创 24.手势识别之UIPanGestureRecognizer
UIPanGestureRecognizer它是拖动手势, 使用和前面的手势类似, 下面我们学习如何使用它1. UIPanGestureRecognizer的创建我们实现一个图片随着手指的移动而移动:import UIKitclass ViewController: UIViewController { var imageView: UIImageView! override func
2016-03-11 17:27:54
1102
原创 23. 手势识别之UIRotationGestureRecognizer
UIRotationGestureRecognizer旋转手势,使用和前面的非常类似, 我们学习如何使用它1. UIRotationGestureRecognizer的创建下面我们来使用它实现一个图片随手势旋转import UIKitclass ViewController: UIViewController { var imageView: UIImageView! override
2016-03-11 17:01:17
662
原创 22.手势识别之UIPinchGestureRecognizer
UIPinchGestureRecognizer可以通过这个手势来获得缩放效果1. UIPinchGestureRecognizer的创建import UIKitclass ViewController: UIViewController { var label: UILabel! override func viewDidLoad() { super.viewDidLo
2016-03-09 13:55:25
1394
原创 21. 手势识别之UITapGestureRecognizer
UITapGestureRecognizer点击手势, 可以设置单击,双击,多击,还可以设置使用几根手指, 下面我们学习如何使用它1.UITapGestureRecognizer的创建import UIKitclass ViewController: UIViewController { var label: UILabel? override func viewDidLoad() {
2016-03-08 22:41:07
770
原创 20. 手势识别之UISwipeGestureRecognizer
手势识别UIGestureRecognizeriOS中, 手势识别主要使用UIGestureRecognizer, 我们一般使用它的子类, 现在我们学习使用UISwipeGestureRecognizer滑动手势1. UISwipeGestureRecognizer的使用import UIKitclass ViewController: UIViewController { var label
2016-03-08 22:07:44
634
原创 19.CoreMotion(陀螺仪)
CoreMotionCoreMotion可以监听x,y,z上个方向的加速度, 它的使用还是蛮简单的, 下面我们学习如何使用它1. 使用CoreMotion控制小球import UIKitimport CoreMotionclass ViewController: UIViewController, UIAccelerometerDelegate { let motionManager = C
2016-03-08 11:14:00
621
原创 18.UIWebView
UIWebViewUIWebView看名字就知道是可以加载web页面的控件, 下面我们学习如何使用它1. UIWebView的创建let webView = UIWebView(frame: self.view.bounds)webView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.youkuaiyun.com/")!))webView.
2016-03-01 20:15:16
407
原创 17.UITextView
UITextViewUITextView是多行文本输入控件, 它的很多属性和UILabel是一样的,如设置字体,颜色,对齐方式.我们将学习它的其它属性和方法1. UITextView的创建let textView = UITextView(frame: CGRect(x: 20, y: 50, width: 300, height: 200))textView.editable = truete
2016-02-29 17:21:03
633
原创 16.UISegmentedControl
UISegmentedControlUISegmentedControl怎么说呢, 就是一个可以选择的控件,下面运行实例的时候就知道它是什么样的了, 下面我们学习如何使用它1. UISegmentedControl创建let segmentedControl = UISegmentedControl(items: ["帅哥", "美女"])segmentedControl.center.x = s
2016-02-29 12:32:14
678
原创 15.UIScrollView
UIScrollViewUIScrollView用于当视图太大时,可以滚动来浏览整个界面, 下面我们学习如何使用它,并实现一个引导页.1. UIScrollView的创建let scrollView = UIScrollView(frame: self.view.bounds)self.view.addSubview(scrollView)let provenceImg = UIImageView
2016-02-28 10:25:35
432
原创 14.UIPickerView
UIPickerViewUIPickerView就是一个滑动选择控件,下面我们学习如何使用它1. UIPickerView的创建let pickerView = UIPickerView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 500))self.view.addSubview(pickerView)运行程序
2016-02-27 20:44:54
435
原创 13.UIStepper
UIStepperUIStepper是一个数字调节控件,非常简单的一个控件, 下面我们学习如何使用它1. UIStepper的创建let stepper = UIStepper(frame: CGRect(x: 10, y: 20, width: 300, height: 300))self.view.addSubview(stepper)运行程序 2. UIStepper的值改变监听和UISl
2016-02-27 19:42:24
420
原创 12.UISwitch
UISwitchUISwitch就是一个开关, 用起来也非常简单, 下面我们学习如何使用它1. UISwitch创建let switchView = UISwitch(frame: CGRect(x: 200, y: 20, width: 300, height: 300))switchView.on = falseself.view.addSubview(switchView)运行程序:
2016-02-27 12:35:20
495
原创 11.UISlider
UISliderUISlider就一滑块,我们学习如何使用它1. UISlider的创建let slider = UISlider(frame: CGRect(x: 10, y: 30, width: 350, height: 30))slider.minimumValue = 0slider.maximumValue = 100slider.value = 20slider.minimum
2016-02-27 11:05:50
573
原创 10.UIProgressView
UIProgressViewUIProgressView看名字就知道这是一个进度条了, 使用非常简单, 下面我们学习如何使用它1. UIProgressView创建let progressView = UIProgressView()progressView.progressViewStyle = .DefaultprogressView.frame.size.width = 200progr
2016-02-27 10:58:02
625
原创 9. UIActionSheet
UIActionSheetUIActionSheet和UIAlertView非常类似, 我们将学习如何使用它1.UIActionSheet创建import UIKitclass ViewController: UIViewController, UIActionSheetDelegate { override func viewDidLoad() { super.viewDid
2016-02-26 18:52:20
672
原创 8.UIAlertView
UIAlertViewUIAlertView可用来显示提示信息,下面我们学习如何使用它1. UIAlertView的创建let alertView = UIAlertView()alertView.delegate = selfalertView.title = "摸着你的良心回答"alertView.message = "邪恶枫叶帅吗?"alertView.addButtonWithTit
2016-02-26 13:19:49
382
原创 7.UITextField
UITextFieldUITextField即文本框,可以输入文本.我们将学习它的使用1. UITextField创建import UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let textField = UITex
2016-02-26 11:06:51
517
原创 6.UITabBarController
UITabBarControllerUITabBarController实现底部切换的效果非常方便,如下图 下面我们学习如何实现这种效果1. UITabBarController的创建AppDelegate.swift中,我们创建一个UITabBarControllerfunc application(application: UIApplication, didFinishLaunchingWi
2016-02-25 11:58:14
390
原创 5.UINavigationController
UINavigationControllerUINavigationController即有导航栏的的UIViewController.它可以非常方便的进行界面的切换.1. UINavigationController的创建首先我们创建一个UINavigationController, 修改AppDelegate.swift// ViewController.swiftfunc applicati
2016-02-24 21:17:36
477
原创 4.UIViewController
UIViewControllerUIViewController简单的说就是视图控制器, 用于view的管理, 数据的处理.1. UIViewController的跳转(无导航栏)利用前面学习的知识, 我们实现下面的需求:ViewController中有一个UIButton, 点击UIButton跳转到ViewController2ViewController2中也有一个UIButton, 点击
2016-02-23 19:34:20
419
原创 3.UIButton
UIButtonUIButton即按钮控件, 下面我们学习使用它1. 创建并设置不同状态按钮的文字和颜色import UIKitimport AlamofireImageclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let bu
2016-02-23 17:18:26
393
原创 2.UIImageView
UIImageViewUIImageView用于显示图片,我们将学习UIImageView的常用方法.1. 添加一张图片到项目中为什么使用这张图片呢? 因为本人是射手座!2. 创建UIImageViewimport UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.
2016-02-23 12:07:09
613
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人