├── .DS_Store ├── 2.pic.png ├── 3.pic.png ├── RTPhotoPicker ├── .DS_Store ├── Assets.xcassets │ ├── .DS_Store │ ├── compose_pic_add.imageset │ │ ├── compose_pic_add@2x.png │ │ ├── compose_pic_add@3x.png │ │ └── Contents.json │ ├── compose_photo_close.imageset │ │ ├── compose_photo_close@2x.png │ │ └── Contents.json │ ├── compose_pic_add_highlighted.imageset │ │ ├── compose_pic_add_highlighted@2x.png │ │ ├── compose_pic_add_highlighted@3x.png │ │ └── Contents.json │ ├── Brand Assets.launchimage │ │ └── Contents.json │ └── AppIcon.appiconset │ │ └── Contents.json ├── ViewController.swift ├── UImage+Category.swift ├── Info.plist ├── Base.lproj │ ├── Main.storyboard │ └── LaunchScreen.storyboard ├── AppDelegate.swift └── PhotoPickerController.swift ├── RTPhotoPicker.xcodeproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── project.pbxproj ├── README.md ├── LICENSE └── .gitignore /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeXiaoQiang/RTPhotoPicker/HEAD/.DS_Store -------------------------------------------------------------------------------- /2.pic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeXiaoQiang/RTPhotoPicker/HEAD/2.pic.png -------------------------------------------------------------------------------- /3.pic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeXiaoQiang/RTPhotoPicker/HEAD/3.pic.png -------------------------------------------------------------------------------- /RTPhotoPicker/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeXiaoQiang/RTPhotoPicker/HEAD/RTPhotoPicker/.DS_Store -------------------------------------------------------------------------------- /RTPhotoPicker/Assets.xcassets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeXiaoQiang/RTPhotoPicker/HEAD/RTPhotoPicker/Assets.xcassets/.DS_Store -------------------------------------------------------------------------------- /RTPhotoPicker/Assets.xcassets/compose_pic_add.imageset/compose_pic_add@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeXiaoQiang/RTPhotoPicker/HEAD/RTPhotoPicker/Assets.xcassets/compose_pic_add.imageset/compose_pic_add@2x.png -------------------------------------------------------------------------------- /RTPhotoPicker/Assets.xcassets/compose_pic_add.imageset/compose_pic_add@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeXiaoQiang/RTPhotoPicker/HEAD/RTPhotoPicker/Assets.xcassets/compose_pic_add.imageset/compose_pic_add@3x.png -------------------------------------------------------------------------------- /RTPhotoPicker/Assets.xcassets/compose_photo_close.imageset/compose_photo_close@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeXiaoQiang/RTPhotoPicker/HEAD/RTPhotoPicker/Assets.xcassets/compose_photo_close.imageset/compose_photo_close@2x.png -------------------------------------------------------------------------------- /RTPhotoPicker.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RTPhotoPicker/Assets.xcassets/compose_pic_add_highlighted.imageset/compose_pic_add_highlighted@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeXiaoQiang/RTPhotoPicker/HEAD/RTPhotoPicker/Assets.xcassets/compose_pic_add_highlighted.imageset/compose_pic_add_highlighted@2x.png -------------------------------------------------------------------------------- /RTPhotoPicker/Assets.xcassets/compose_pic_add_highlighted.imageset/compose_pic_add_highlighted@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeXiaoQiang/RTPhotoPicker/HEAD/RTPhotoPicker/Assets.xcassets/compose_pic_add_highlighted.imageset/compose_pic_add_highlighted@3x.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RTPhotoPicker 2 | 图片选择器swift版 3 | 4 | 简单的图片选择器 5 | ====================== 6 | 可以无限制的添加图片 7 | ------------------ 8 | ![image](https://github.com/codeXiaoQiang/PhotoPicker/blob/master/2.pic.png) 9 | 10 | 11 | 实现抖动删除 12 | ---------------- 13 | ![image](https://github.com/codeXiaoQiang/PhotoPicker/blob/master/3.pic.png) -------------------------------------------------------------------------------- /RTPhotoPicker/Assets.xcassets/compose_photo_close.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "compose_photo_close@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /RTPhotoPicker/Assets.xcassets/compose_pic_add.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "compose_pic_add@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "compose_pic_add@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /RTPhotoPicker/Assets.xcassets/Brand Assets.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "minimum-system-version" : "7.0", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "orientation" : "portrait", 11 | "idiom" : "iphone", 12 | "minimum-system-version" : "7.0", 13 | "subtype" : "retina4", 14 | "scale" : "2x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /RTPhotoPicker/Assets.xcassets/compose_pic_add_highlighted.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "compose_pic_add_highlighted@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "compose_pic_add_highlighted@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /RTPhotoPicker/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // RTPhotoPicker 4 | // 5 | // Created by yangtao on 3/1/16. 6 | // Copyright © 2016 yangtao. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /RTPhotoPicker/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /RTPhotoPicker/UImage+Category.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UImage+Category.swift 3 | // RTPhotoPicker 4 | // 5 | // Created by yangtao on 3/1/16. 6 | // Copyright © 2016 yangtao. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension UIImage 12 | { 13 | /** 14 | 根据传入的宽度生成一张图片 15 | 按照图片的宽高比来压缩以前的图片 16 | 17 | :param: width 制定宽度 18 | */ 19 | func imageWithScale(width: CGFloat) -> UIImage 20 | { 21 | // 1.根据宽度计算高度 22 | let height = width * size.height / size.width 23 | 24 | // 2.按照宽高比绘制一张新的图片 25 | let currentSize = CGSize(width: width, height: height) 26 | UIGraphicsBeginImageContext(currentSize) 27 | drawInRect(CGRect(origin: CGPointZero, size: currentSize)) 28 | let newImage = UIGraphicsGetImageFromCurrentImageContext() 29 | UIGraphicsEndImageContext() 30 | 31 | return newImage 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 codeXiaoQiang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /RTPhotoPicker/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/screenshots 64 | -------------------------------------------------------------------------------- /RTPhotoPicker/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /RTPhotoPicker/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /RTPhotoPicker/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // RTPhotoPicker 4 | // 5 | // Created by yangtao on 3/1/16. 6 | // Copyright © 2016 yangtao. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | let pickerVc = PhotoPickerController() 20 | 21 | window = UIWindow() 22 | window?.backgroundColor = UIColor.whiteColor() 23 | window?.frame = UIScreen.mainScreen().bounds 24 | window?.rootViewController = pickerVc 25 | window?.makeKeyAndVisible() 26 | return true 27 | } 28 | 29 | func applicationWillResignActive(application: UIApplication) { 30 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 31 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 32 | } 33 | 34 | func applicationDidEnterBackground(application: UIApplication) { 35 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 36 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 37 | } 38 | 39 | func applicationWillEnterForeground(application: UIApplication) { 40 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 41 | } 42 | 43 | func applicationDidBecomeActive(application: UIApplication) { 44 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 45 | } 46 | 47 | func applicationWillTerminate(application: UIApplication) { 48 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 49 | } 50 | 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /RTPhotoPicker/PhotoPickerController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PhotoPickerController.swift 3 | // RTPhotoPicker 4 | // 5 | // Created by yangtao on 3/1/16. 6 | // Copyright © 2016 yangtao. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | private let photoCollectionCellIdentifier = "photoCollectionCellIdentifier" 11 | class PhotoPickerController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | setupUI() 17 | } 18 | 19 | private func setupUI() { 20 | 21 | view.addSubview(photoCollectionView) 22 | photoCollectionView.frame = UIScreen.mainScreen().bounds 23 | } 24 | 25 | override func didReceiveMemoryWarning() { 26 | super.didReceiveMemoryWarning() 27 | // Dispose of any resources that can be recreated. 28 | } 29 | 30 | 31 | lazy var photoCollectionView:UICollectionView = { 32 | let photoCollectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: photoCollectionViewLayout()) 33 | 34 | photoCollectionView.registerClass(photoCollectionViewCell.self, forCellWithReuseIdentifier: photoCollectionCellIdentifier) 35 | photoCollectionView.dataSource = self 36 | //photoCollectionView.backgroundColor = UIColor.greenColor() 37 | return photoCollectionView 38 | }() 39 | 40 | //用于保存图片 41 | private lazy var pictureImages = [UIImage]() 42 | } 43 | 44 | 45 | private class photoCollectionViewLayout: UICollectionViewFlowLayout { 46 | 47 | override func prepareLayout() { 48 | super.prepareLayout() 49 | 50 | //设置photoCollectionViewLayout的布局 51 | minimumInteritemSpacing = 10 52 | minimumLineSpacing = 10 53 | itemSize = CGSizeMake(80, 80) 54 | 55 | //设置与photoCollectionView的间距 56 | sectionInset = UIEdgeInsetsMake(10, 10, 10, 10) 57 | } 58 | } 59 | 60 | extension PhotoPickerController: UICollectionViewDataSource, PhotoSelectorCellDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate { 61 | 62 | func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 63 | return pictureImages.count + 1 64 | } 65 | 66 | func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 67 | 68 | let cell = collectionView.dequeueReusableCellWithReuseIdentifier(photoCollectionCellIdentifier, forIndexPath: indexPath) as! photoCollectionViewCell 69 | cell.PhotoCellDelegate = self 70 | 71 | cell.image = (pictureImages.count == indexPath.item) ? nil : pictureImages[indexPath.item] // 0 1 72 | return cell 73 | } 74 | 75 | func photoDidAddSelector(cell: photoCollectionViewCell) { 76 | 77 | if !UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary) { 78 | 79 | print("不能打开相册") 80 | return 81 | } 82 | 83 | //打开相册 84 | let vc = UIImagePickerController() 85 | //设置图片代理 86 | vc.delegate = self 87 | //允许用户编辑图片 88 | vc.editing = true 89 | presentViewController(vc, animated: true, completion: nil) 90 | } 91 | 92 | func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) { 93 | 94 | //对图片进行压缩,进行内存优化 95 | let newImage = image.imageWithScale(UIScreen.mainScreen().bounds.width) 96 | print("image= \(image)"); 97 | // 1.将当前选中的图片添加到数组中 98 | pictureImages.append(newImage) 99 | photoCollectionView.reloadData() 100 | 101 | picker.dismissViewControllerAnimated(true, completion: nil) 102 | } 103 | 104 | 105 | func photoDidRemoveSelector(cell: photoCollectionViewCell) { 106 | 107 | let index = photoCollectionView.indexPathForCell(cell) 108 | pictureImages.removeAtIndex(index!.item) 109 | photoCollectionView.reloadData() 110 | } 111 | } 112 | 113 | @objc 114 | protocol PhotoSelectorCellDelegate : NSObjectProtocol 115 | { 116 | optional func photoDidAddSelector(cell: photoCollectionViewCell) 117 | optional func photoDidRemoveSelector(cell: photoCollectionViewCell) 118 | } 119 | 120 | class photoCollectionViewCell:UICollectionViewCell { 121 | 122 | weak var PhotoCellDelegate: PhotoSelectorCellDelegate? 123 | //开放接口提供数据 124 | var image: UIImage? 125 | { 126 | didSet{ 127 | if image != nil{ 128 | removeButton.hidden = false 129 | addButton.setBackgroundImage(image!, forState: UIControlState.Normal) 130 | addButton.userInteractionEnabled = false 131 | }else 132 | { 133 | removeButton.hidden = true 134 | addButton.userInteractionEnabled = true 135 | addButton.setBackgroundImage(UIImage(named: "compose_pic_add"), forState: UIControlState.Normal) 136 | } 137 | } 138 | } 139 | 140 | override init(frame: CGRect) { 141 | super.init(frame: frame) 142 | 143 | setupUI() 144 | } 145 | 146 | private func setupUI() { 147 | 148 | // 1.添加子控件 149 | contentView.addSubview(addButton) 150 | contentView.addSubview(removeButton) 151 | 152 | // 2.布局子控件 153 | addButton.translatesAutoresizingMaskIntoConstraints = false 154 | removeButton.translatesAutoresizingMaskIntoConstraints = false 155 | var cons = [NSLayoutConstraint]() 156 | cons += NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[addButton]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["addButton": addButton]) 157 | cons += NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[addButton]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["addButton": addButton]) 158 | 159 | cons += NSLayoutConstraint.constraintsWithVisualFormat("H:[removeButton]-2-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["removeButton": removeButton]) 160 | cons += NSLayoutConstraint.constraintsWithVisualFormat("V:|-2-[removeButton]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["removeButton": removeButton]) 161 | 162 | contentView.addConstraints(cons) 163 | 164 | } 165 | 166 | // MARK: - 懒加载 167 | private lazy var removeButton: UIButton = { 168 | let btn = UIButton() 169 | btn.hidden = true 170 | btn.setBackgroundImage(UIImage(named: "compose_photo_close"), forState: UIControlState.Normal) 171 | btn.addTarget(self, action: "removeBtnClick", forControlEvents: UIControlEvents.TouchUpInside) 172 | return btn 173 | }() 174 | private lazy var addButton: UIButton = { 175 | let btn = UIButton() 176 | btn.imageView?.contentMode = UIViewContentMode.ScaleAspectFill 177 | btn.setBackgroundImage(UIImage(named: "compose_pic_add"), forState: UIControlState.Normal) 178 | btn.setBackgroundImage(UIImage(named: "compose_pic_add_highlighted"), forState: UIControlState.Highlighted) 179 | btn.addTarget(self, action: "addBtnClick", forControlEvents: UIControlEvents.TouchUpInside) 180 | return btn 181 | }() 182 | 183 | func addBtnClick() 184 | { 185 | PhotoCellDelegate?.photoDidAddSelector!(self) 186 | print(__FUNCTION__) 187 | } 188 | 189 | func removeBtnClick() 190 | { 191 | PhotoCellDelegate?.photoDidRemoveSelector!(self) 192 | print(__FUNCTION__) 193 | 194 | } 195 | 196 | required init?(coder aDecoder: NSCoder) { 197 | fatalError("init(coder:) has not been implemented") 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /RTPhotoPicker.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 9DECA53F1C85397D00B2D490 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DECA53E1C85397D00B2D490 /* AppDelegate.swift */; }; 11 | 9DECA5411C85397D00B2D490 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DECA5401C85397D00B2D490 /* ViewController.swift */; }; 12 | 9DECA5441C85397D00B2D490 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9DECA5421C85397D00B2D490 /* Main.storyboard */; }; 13 | 9DECA5461C85397D00B2D490 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9DECA5451C85397D00B2D490 /* Assets.xcassets */; }; 14 | 9DECA5491C85397D00B2D490 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9DECA5471C85397D00B2D490 /* LaunchScreen.storyboard */; }; 15 | 9DECA5511C853AD800B2D490 /* PhotoPickerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DECA5501C853AD800B2D490 /* PhotoPickerController.swift */; }; 16 | 9DECA5581C8560C700B2D490 /* UImage+Category.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DECA5571C8560C700B2D490 /* UImage+Category.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 9DECA53B1C85397D00B2D490 /* RTPhotoPicker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RTPhotoPicker.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 9DECA53E1C85397D00B2D490 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | 9DECA5401C85397D00B2D490 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 23 | 9DECA5431C85397D00B2D490 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 24 | 9DECA5451C85397D00B2D490 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | 9DECA5481C85397D00B2D490 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | 9DECA54A1C85397D00B2D490 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | 9DECA5501C853AD800B2D490 /* PhotoPickerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoPickerController.swift; sourceTree = ""; }; 28 | 9DECA5571C8560C700B2D490 /* UImage+Category.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UImage+Category.swift"; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 9DECA5381C85397D00B2D490 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 9DECA5321C85397D00B2D490 = { 43 | isa = PBXGroup; 44 | children = ( 45 | 9DECA53D1C85397D00B2D490 /* RTPhotoPicker */, 46 | 9DECA53C1C85397D00B2D490 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 9DECA53C1C85397D00B2D490 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 9DECA53B1C85397D00B2D490 /* RTPhotoPicker.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 9DECA53D1C85397D00B2D490 /* RTPhotoPicker */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 9DECA53E1C85397D00B2D490 /* AppDelegate.swift */, 62 | 9DECA5401C85397D00B2D490 /* ViewController.swift */, 63 | 9DECA5421C85397D00B2D490 /* Main.storyboard */, 64 | 9DECA5451C85397D00B2D490 /* Assets.xcassets */, 65 | 9DECA5471C85397D00B2D490 /* LaunchScreen.storyboard */, 66 | 9DECA54A1C85397D00B2D490 /* Info.plist */, 67 | 9DECA5501C853AD800B2D490 /* PhotoPickerController.swift */, 68 | 9DECA5571C8560C700B2D490 /* UImage+Category.swift */, 69 | ); 70 | path = RTPhotoPicker; 71 | sourceTree = ""; 72 | }; 73 | /* End PBXGroup section */ 74 | 75 | /* Begin PBXNativeTarget section */ 76 | 9DECA53A1C85397D00B2D490 /* RTPhotoPicker */ = { 77 | isa = PBXNativeTarget; 78 | buildConfigurationList = 9DECA54D1C85397D00B2D490 /* Build configuration list for PBXNativeTarget "RTPhotoPicker" */; 79 | buildPhases = ( 80 | 9DECA5371C85397D00B2D490 /* Sources */, 81 | 9DECA5381C85397D00B2D490 /* Frameworks */, 82 | 9DECA5391C85397D00B2D490 /* Resources */, 83 | ); 84 | buildRules = ( 85 | ); 86 | dependencies = ( 87 | ); 88 | name = RTPhotoPicker; 89 | productName = RTPhotoPicker; 90 | productReference = 9DECA53B1C85397D00B2D490 /* RTPhotoPicker.app */; 91 | productType = "com.apple.product-type.application"; 92 | }; 93 | /* End PBXNativeTarget section */ 94 | 95 | /* Begin PBXProject section */ 96 | 9DECA5331C85397D00B2D490 /* Project object */ = { 97 | isa = PBXProject; 98 | attributes = { 99 | LastSwiftUpdateCheck = 0720; 100 | LastUpgradeCheck = 0720; 101 | ORGANIZATIONNAME = yangtao; 102 | TargetAttributes = { 103 | 9DECA53A1C85397D00B2D490 = { 104 | CreatedOnToolsVersion = 7.2; 105 | }; 106 | }; 107 | }; 108 | buildConfigurationList = 9DECA5361C85397D00B2D490 /* Build configuration list for PBXProject "RTPhotoPicker" */; 109 | compatibilityVersion = "Xcode 3.2"; 110 | developmentRegion = English; 111 | hasScannedForEncodings = 0; 112 | knownRegions = ( 113 | en, 114 | Base, 115 | ); 116 | mainGroup = 9DECA5321C85397D00B2D490; 117 | productRefGroup = 9DECA53C1C85397D00B2D490 /* Products */; 118 | projectDirPath = ""; 119 | projectRoot = ""; 120 | targets = ( 121 | 9DECA53A1C85397D00B2D490 /* RTPhotoPicker */, 122 | ); 123 | }; 124 | /* End PBXProject section */ 125 | 126 | /* Begin PBXResourcesBuildPhase section */ 127 | 9DECA5391C85397D00B2D490 /* Resources */ = { 128 | isa = PBXResourcesBuildPhase; 129 | buildActionMask = 2147483647; 130 | files = ( 131 | 9DECA5491C85397D00B2D490 /* LaunchScreen.storyboard in Resources */, 132 | 9DECA5461C85397D00B2D490 /* Assets.xcassets in Resources */, 133 | 9DECA5441C85397D00B2D490 /* Main.storyboard in Resources */, 134 | ); 135 | runOnlyForDeploymentPostprocessing = 0; 136 | }; 137 | /* End PBXResourcesBuildPhase section */ 138 | 139 | /* Begin PBXSourcesBuildPhase section */ 140 | 9DECA5371C85397D00B2D490 /* Sources */ = { 141 | isa = PBXSourcesBuildPhase; 142 | buildActionMask = 2147483647; 143 | files = ( 144 | 9DECA5511C853AD800B2D490 /* PhotoPickerController.swift in Sources */, 145 | 9DECA5581C8560C700B2D490 /* UImage+Category.swift in Sources */, 146 | 9DECA5411C85397D00B2D490 /* ViewController.swift in Sources */, 147 | 9DECA53F1C85397D00B2D490 /* AppDelegate.swift in Sources */, 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | }; 151 | /* End PBXSourcesBuildPhase section */ 152 | 153 | /* Begin PBXVariantGroup section */ 154 | 9DECA5421C85397D00B2D490 /* Main.storyboard */ = { 155 | isa = PBXVariantGroup; 156 | children = ( 157 | 9DECA5431C85397D00B2D490 /* Base */, 158 | ); 159 | name = Main.storyboard; 160 | sourceTree = ""; 161 | }; 162 | 9DECA5471C85397D00B2D490 /* LaunchScreen.storyboard */ = { 163 | isa = PBXVariantGroup; 164 | children = ( 165 | 9DECA5481C85397D00B2D490 /* Base */, 166 | ); 167 | name = LaunchScreen.storyboard; 168 | sourceTree = ""; 169 | }; 170 | /* End PBXVariantGroup section */ 171 | 172 | /* Begin XCBuildConfiguration section */ 173 | 9DECA54B1C85397D00B2D490 /* Debug */ = { 174 | isa = XCBuildConfiguration; 175 | buildSettings = { 176 | ALWAYS_SEARCH_USER_PATHS = NO; 177 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 178 | CLANG_CXX_LIBRARY = "libc++"; 179 | CLANG_ENABLE_MODULES = YES; 180 | CLANG_ENABLE_OBJC_ARC = YES; 181 | CLANG_WARN_BOOL_CONVERSION = YES; 182 | CLANG_WARN_CONSTANT_CONVERSION = YES; 183 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 184 | CLANG_WARN_EMPTY_BODY = YES; 185 | CLANG_WARN_ENUM_CONVERSION = YES; 186 | CLANG_WARN_INT_CONVERSION = YES; 187 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 188 | CLANG_WARN_UNREACHABLE_CODE = YES; 189 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 190 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 191 | COPY_PHASE_STRIP = NO; 192 | DEBUG_INFORMATION_FORMAT = dwarf; 193 | ENABLE_STRICT_OBJC_MSGSEND = YES; 194 | ENABLE_TESTABILITY = YES; 195 | GCC_C_LANGUAGE_STANDARD = gnu99; 196 | GCC_DYNAMIC_NO_PIC = NO; 197 | GCC_NO_COMMON_BLOCKS = YES; 198 | GCC_OPTIMIZATION_LEVEL = 0; 199 | GCC_PREPROCESSOR_DEFINITIONS = ( 200 | "DEBUG=1", 201 | "$(inherited)", 202 | ); 203 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 204 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 205 | GCC_WARN_UNDECLARED_SELECTOR = YES; 206 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 207 | GCC_WARN_UNUSED_FUNCTION = YES; 208 | GCC_WARN_UNUSED_VARIABLE = YES; 209 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 210 | MTL_ENABLE_DEBUG_INFO = YES; 211 | ONLY_ACTIVE_ARCH = YES; 212 | SDKROOT = iphoneos; 213 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 214 | }; 215 | name = Debug; 216 | }; 217 | 9DECA54C1C85397D00B2D490 /* Release */ = { 218 | isa = XCBuildConfiguration; 219 | buildSettings = { 220 | ALWAYS_SEARCH_USER_PATHS = NO; 221 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 222 | CLANG_CXX_LIBRARY = "libc++"; 223 | CLANG_ENABLE_MODULES = YES; 224 | CLANG_ENABLE_OBJC_ARC = YES; 225 | CLANG_WARN_BOOL_CONVERSION = YES; 226 | CLANG_WARN_CONSTANT_CONVERSION = YES; 227 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 228 | CLANG_WARN_EMPTY_BODY = YES; 229 | CLANG_WARN_ENUM_CONVERSION = YES; 230 | CLANG_WARN_INT_CONVERSION = YES; 231 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 232 | CLANG_WARN_UNREACHABLE_CODE = YES; 233 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 234 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 235 | COPY_PHASE_STRIP = NO; 236 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 237 | ENABLE_NS_ASSERTIONS = NO; 238 | ENABLE_STRICT_OBJC_MSGSEND = YES; 239 | GCC_C_LANGUAGE_STANDARD = gnu99; 240 | GCC_NO_COMMON_BLOCKS = YES; 241 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 242 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 243 | GCC_WARN_UNDECLARED_SELECTOR = YES; 244 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 245 | GCC_WARN_UNUSED_FUNCTION = YES; 246 | GCC_WARN_UNUSED_VARIABLE = YES; 247 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 248 | MTL_ENABLE_DEBUG_INFO = NO; 249 | SDKROOT = iphoneos; 250 | VALIDATE_PRODUCT = YES; 251 | }; 252 | name = Release; 253 | }; 254 | 9DECA54E1C85397D00B2D490 /* Debug */ = { 255 | isa = XCBuildConfiguration; 256 | buildSettings = { 257 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 258 | CLANG_ENABLE_MODULES = YES; 259 | INFOPLIST_FILE = RTPhotoPicker/Info.plist; 260 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 261 | PRODUCT_BUNDLE_IDENTIFIER = rain.yang.RTPhotoPicker; 262 | PRODUCT_NAME = "$(TARGET_NAME)"; 263 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 264 | }; 265 | name = Debug; 266 | }; 267 | 9DECA54F1C85397D00B2D490 /* Release */ = { 268 | isa = XCBuildConfiguration; 269 | buildSettings = { 270 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 271 | CLANG_ENABLE_MODULES = YES; 272 | INFOPLIST_FILE = RTPhotoPicker/Info.plist; 273 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 274 | PRODUCT_BUNDLE_IDENTIFIER = rain.yang.RTPhotoPicker; 275 | PRODUCT_NAME = "$(TARGET_NAME)"; 276 | }; 277 | name = Release; 278 | }; 279 | /* End XCBuildConfiguration section */ 280 | 281 | /* Begin XCConfigurationList section */ 282 | 9DECA5361C85397D00B2D490 /* Build configuration list for PBXProject "RTPhotoPicker" */ = { 283 | isa = XCConfigurationList; 284 | buildConfigurations = ( 285 | 9DECA54B1C85397D00B2D490 /* Debug */, 286 | 9DECA54C1C85397D00B2D490 /* Release */, 287 | ); 288 | defaultConfigurationIsVisible = 0; 289 | defaultConfigurationName = Release; 290 | }; 291 | 9DECA54D1C85397D00B2D490 /* Build configuration list for PBXNativeTarget "RTPhotoPicker" */ = { 292 | isa = XCConfigurationList; 293 | buildConfigurations = ( 294 | 9DECA54E1C85397D00B2D490 /* Debug */, 295 | 9DECA54F1C85397D00B2D490 /* Release */, 296 | ); 297 | defaultConfigurationIsVisible = 0; 298 | defaultConfigurationName = Release; 299 | }; 300 | /* End XCConfigurationList section */ 301 | }; 302 | rootObject = 9DECA5331C85397D00B2D490 /* Project object */; 303 | } 304 | --------------------------------------------------------------------------------