Skip to content
This repository was archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Huang committed Jul 13, 2016
0 parents commit cd759f8
Show file tree
Hide file tree
Showing 71 changed files with 5,217 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
#Pods/
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
branches:
only:
- travis-enable
language: objective-c
osx_image: xcode7.3
install:
- gem install xcpretty -N --no-ri --no-rdoc
script:
- set -o pipefail && xcodebuild -project YangMingShanDemo.xcodeproj -scheme YangMingShanDemo -sdk iphonesimulator9.3 -destination 'platform=iOS Simulator,name=iPhone 6s,OS=9.3' build test | xcpretty -c
26 changes: 26 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright 2016 Yahoo Inc.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

* Neither the name of the Yahoo Inc. nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL YAHOO! INC. BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
256 changes: 256 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
<img src="media/[email protected]">
=====
[![Build Status](https://travis-ci.org/yahoo/YangMingShan.svg?branch=master)](https://travis-ci.org/yahoo/YangMingShan)
[![CocoaPods](https://img.shields.io/cocoapods/v/YangMingShan.svg?maxAge=2592000?style=flat-square)](https://cocoapods.org/?q=yangmingshan)

YangMingShan is a collection of iOS UI components that we created while building Yahoo apps. The reason we open source it is to share useful and common componets with the community. Feel free to open the feature request ticket for new UI component you see on Yahoo apps or send pull-request to benefit open source community.

Installation
-------

YangMingShan can be installed via [CocoaPods](http://cocoapods.org/). Simply add

```ruby
pod 'YangMingShan'
```

to your Podfile.

The Components
-------

### YMSPhotoPicker

YMSPhotoPicker is an UIComponent that let you select mutilple photos from your albums. You can also take a photo inside YMSPhotoPicker and select it with other photos. It has the exposed theme YMSPhotoPickerTheme that you can customize several parts of YMSPhotoPicker.

<img src="media/ymsphotopicker-demo.gif" alt="Square Cash Style Bar" width="300"/>
<img src="media/ymsphotopicker-theme.gif" alt="Square Cash Style Bar" width="300"/>

#### Usage
#####Objective-C

Import

```objective-c
@import YangMingShan;
```

Add delegate to your view controller

```objective-c
@interface YourViewController ()<YMSPhotoPickerViewControllerDelegate>
```
Present default photo picker. Note it is only available for single selection
```objective-c
[self yms_presentAlbumPhotoViewWithDelegate:self];
```

Or init picker with limited photo selection of 10

```objective-c
YMSPhotoPickerViewController *pickerViewController = [[YMSPhotoPickerViewController alloc] init];
pickerViewController.numberOfPhotoToSelect = 10;
```

With customized theme
```objective-c
UIColor *customColor = [UIColor colorWithRed:64.0/255.0 green:0.0 blue:144.0/255.0 alpha:1.0];
UIColor *customCameraColor = [UIColor colorWithRed:86.0/255.0 green:1.0/255.0 blue:236.0/255.0 alpha:1.0];

pickerViewController.theme.titleLabelTextColor = [UIColor whiteColor];
pickerViewController.theme.navigationBarBackgroundColor = customColor;
pickerViewController.theme.tintColor = [UIColor whiteColor];
pickerViewController.theme.orderTintColor = customCameraColor;
pickerViewController.theme.cameraVeilColor = customCameraColor;
pickerViewController.theme.cameraIconColor = [UIColor whiteColor];
pickerViewController.theme.statusBarStyle = UIStatusBarStyleLightContent;
```
Present customized picker
```objective-c
[self yms_presentCustomAlbumPhotoView:pickerViewController delegate:self];
```

Implement photoPickerViewControllerDidReceivePhotoAlbumAccessDenied: and photoPickerViewControllerDidReceiveCameraAccessDenied: to obesrve photo album and camera access denied occur

```objective-c
- (void)photoPickerViewControllerDidReceivePhotoAlbumAccessDenied:(YMSPhotoPickerViewController *)picker
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Allow photo album access?", nil) message:NSLocalizedString(@"Need your permission to access photo albumbs", nil) preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Settings", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
[alertController addAction:dismissAction];
[alertController addAction:settingsAction];

[self presentViewController:alertController animated:YES completion:nil];
}

- (void)photoPickerViewControllerDidReceiveCameraAccessDenied:(YMSPhotoPickerViewController *)picker
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Allow camera access?", nil) message:NSLocalizedString(@"Need your permission to take a photo", nil) preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Settings", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
[alertController addAction:dismissAction];
[alertController addAction:settingsAction];

// The access denied of camera is always happened on picker, present alert on it to follow the view hierarchy
[picker presentViewController:alertController animated:YES completion:nil];
}
```

Implement photoPickerViewController:didFinishPickingImages: while you expect there are mutiple photo selections

```objective-c
- (void)photoPickerViewController:(YMSPhotoPickerViewController *)picker didFinishPickingImages:(NSArray *)photoAssets
{
[picker dismissViewControllerAnimated:YES completion:^() {
// Remember images you get here is PHAsset array, you need to implement PHImageManager to get UIImage data by yourself
PHImageManager *imageManager = [[PHImageManager alloc] init];

PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.networkAccessAllowed = YES;
options.resizeMode = PHImageRequestOptionsResizeModeExact;
options.synchronous = YES;

NSMutableArray *mutableImages = [NSMutableArray array];

for (PHAsset *asset in photoAssets) {
CGSize targetSize = CGSizeMake((CGRectGetWidth(self.collectionView.bounds) - 20*2) * [UIScreen mainScreen].scale, (CGRectGetHeight(self.collectionView.bounds) - 20*2) * [UIScreen mainScreen].scale);
[imageManager requestImageForAsset:asset targetSize:targetSize contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *image, NSDictionary *info) {
[mutableImages addObject:image];
}];
}

// Assign to Array with images
self.images = [mutableImages copy];
}];
}
```

#####Swift

Import

```swift
import YangMingShan
```

Add delegate to your view controller

```swift
class YourViewController: UIViewController, YMSPhotoPickerViewControllerDelegate
```

Present default photo picker. Note it is only available for single selection

```swift
self.yms_presentAlbumPhotoViewWithDelegate(self)
```

Or init picker with limited photo selection of 10

```swift
let pickerViewController = YMSPhotoPickerViewController.init()
pickerViewController.numberOfPhotoToSelect = 10
```

With customized theme

```swift
let customColor = UIColor.init(red: 64.0/255.0, green: 0.0, blue: 144.0/255.0, alpha: 1.0)
let customCameraColor = UIColor.init(red: 86.0/255.0, green: 1.0/255.0, blue: 236.0/255.0, alpha: 1.0)

pickerViewController.theme.titleLabelTextColor = UIColor.whiteColor()
pickerViewController.theme.navigationBarBackgroundColor = customColor
pickerViewController.theme.tintColor = UIColor.whiteColor()
pickerViewController.theme.orderTintColor = customCameraColor
pickerViewController.theme.cameraVeilColor = customCameraColor
pickerViewController.theme.cameraIconColor = UIColor.whiteColor()
pickerViewController.theme.statusBarStyle = .LightContent
```

Present customized picker

```swift
self.yms_presentCustomAlbumPhotoView(pickerViewController, delegate: self)
```

Implement photoPickerViewControllerDidReceivePhotoAlbumAccessDenied(picker:) and photoPickerViewControllerDidReceiveCameraAccessDenied(picker:) to obesrve photo album and camera access denied occur

```swift
func photoPickerViewControllerDidReceivePhotoAlbumAccessDenied(picker: YMSPhotoPickerViewController!) {
let alertController = UIAlertController.init(title: "Allow photo album access?", message: "Need your permission to access photo albumbs", preferredStyle: .Alert)
let dismissAction = UIAlertAction.init(title: "Cancel", style: .Cancel, handler: nil)
let settingsAction = UIAlertAction.init(title: "Settings", style: .Default) { (action) in
UIApplication.sharedApplication().openURL(NSURL.init(string: UIApplicationOpenSettingsURLString)!)
}
alertController.addAction(dismissAction)
alertController.addAction(settingsAction)

self.presentViewController(alertController, animated: true, completion: nil)
}

func photoPickerViewControllerDidReceiveCameraAccessDenied(picker: YMSPhotoPickerViewController!) {
let alertController = UIAlertController.init(title: "Allow camera album access?", message: "Need your permission to take a photo", preferredStyle: .Alert)
let dismissAction = UIAlertAction.init(title: "Cancel", style: .Cancel, handler: nil)
let settingsAction = UIAlertAction.init(title: "Settings", style: .Default) { (action) in
UIApplication.sharedApplication().openURL(NSURL.init(string: UIApplicationOpenSettingsURLString)!)
}
alertController.addAction(dismissAction)
alertController.addAction(settingsAction)

// The access denied of camera is always happened on picker, present alert on it to follow the view hierarchy
picker.presentViewController(alertController, animated: true, completion: nil)
}
```

Implement photoPickerViewController(picker:didFinishPickingImages:) while you expect there are mutiple photo selections

```swift
func photoPickerViewController(picker: YMSPhotoPickerViewController!, didFinishPickingImages photoAssets: [PHAsset]!) {
// Remember images you get here is PHAsset array, you need to implement PHImageManager to get UIImage data by yourself
picker.dismissViewControllerAnimated(true) {
let imageManager = PHImageManager.init()
let options = PHImageRequestOptions.init()
options.deliveryMode = .HighQualityFormat
options.resizeMode = .Exact
options.synchronous = true

let mutableImages: NSMutableArray! = []

for asset: PHAsset in photoAssets
{
let scale = UIScreen.mainScreen().scale
let targetSize = CGSizeMake((CGRectGetWidth(self.collectionView.bounds) - 20*2) * scale, (CGRectGetHeight(self.collectionView.bounds) - 20*2) * scale)
imageManager.requestImageForAsset(asset, targetSize: targetSize, contentMode: .AspectFill, options: options, resultHandler: { (image, info) in
mutableImages.addObject(image!)
})
}
// Assign to Array with images
self.images = mutableImages.copy() as? NSArray
}
}
```

### Instruction

- **Sample Codes** has been written in YangMangShanDemo project. You can read code to know about "How to implement these features in your project". Just use github to clone YangMingShan to your local disk. It should run well with your Xcode.
- **API Reference Documents** > Please refer the [gh-pages](https://yahoo.github.io/YangMingShan/) in YangMingShan project. (Doc/index.html). We use [appledoc](https://github.com/tomaz/appledoc) to generate this document. The command line we generate current document is
```shell
appledoc --output {TARGET_FOLDER} --project-name "YangMingShan" --project-company "Yahoo" --company-id "com.yahoo" --no-warn-undocumented-object --keep-intermediate-files --ignore Private {YANGMINGSHAN_LOCOCAL_ROPOSITORY}

```

### License

This software is free to use under the Yahoo Inc. BSD license.
See the [LICENSE] for license text and copyright information.

[LICENSE]: https://github.com/yahoo/YangMingShan/blob/master/LICENSE.md
21 changes: 21 additions & 0 deletions YangMingShan.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Pod::Spec.new do |s|
s.name = 'YangMingShan'
s.author = { "Team" => "[email protected]" }
s.version = '1.0.0'
s.summary = 'The collection of useful UI components that inspired by Yahoo apps.'
s.homepage = 'https://github.com/yahoo/YangMingShan'
s.license = "Yahoo! Inc. BSD license"
s.source = { :git => '[email protected]:yahoo/YangMingShan.git', :tag => s.version.to_s }
s.requires_arc = true
s.frameworks = ['Foundation', 'UIKit', 'QuartzCore']
s.platform = :ios, '8.0'
s.ios.deployment_target = '8.0'
s.default_subspec = 'YMSPhotoPicker'

s.subspec 'YMSPhotoPicker' do |ss|
ss.source_files = ['YangMingShan/YMSPhotoPicker/*.{h,m}', 'YangMingShan/YMSPhotoPicker/**/*.{h,m}']
ss.resources = ['YangMingShan/YMSPhotoPicker/*.xib', 'YangMingShan/YMSPhotoPicker/YMSPhotoPickerAssets.xcassets']
ss.frameworks = ['Photos', 'AVFoundation']
end

end
29 changes: 29 additions & 0 deletions YangMingShan/YMSPhotoPicker/Private/UIScrollView+YMSAdditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// UIScrollView+YMSAdditions.h
// YangMingShan
//
// Copyright 2016 Yahoo Inc.
// Licensed under the terms of the BSD license. Please see LICENSE file in the project root for terms.
//

#import <UIKit/UIKit.h>

typedef enum : NSUInteger {
YMSScrollViewScrollDirectionUp,
YMSScrollViewScrollDirectionDown,
YMSScrollViewScrollDirectionLeft,
YMSScrollViewScrollDirectionRight,
YMSScrollViewScrollDirectionUnknown
} YMSScrollViewScrollDirection;

@interface UIScrollView(YMSAdditions)

@property (nonatomic, readonly) YMSScrollViewScrollDirection scrollDirection;
@property (nonatomic, readonly) CGPoint lastContentOffset;

/**
* Put yms_scrollViewDidScroll inside scrollViewDidScroll: to update scrollDirection
*/
- (void)yms_scrollViewDidScroll;

@end
Loading

0 comments on commit cd759f8

Please sign in to comment.