杨明山 2.0.1

杨明山 2.0.1

测试测试过的
语言语言 Objective-CObjective C
许可证 BSD
发布最新发布2018年1月

Stewart Wu杨明山Stewart Wu 维护。



杨明山 2.0.1

  • 团队



杨明山是我们构建雅虎应用时创建的一组iOS UI组件。我们将其开源的原因是分享有用的和常见的组件给社区。您可以在雅虎应用中看到的任何新UI组件上免费打开功能请求票据,或发送git请求以造福开源社区。

安装

您可以通过CocoaPods来安装YangMingShan。只需在Podfile中添加以下代码:

pod 'YangMingShan'

组件

A

YMSPhotoPicker

YMSPhotoPicker是一个UI组件,允许您从您的相册中选取多张照片。您也可以在YMSPhotoPicker中拍照并与其他照片一起选取。它还提供了可定制的主题YMSPhotoPickerTheme,您可以自定义YMSPhotoPicker的几个部分。

此软件包中的一些代码是从雅虎即时通讯和雅虎台湾拍卖借鉴的。

Square Cash Style Bar

Square Cash Style Bar

用法

NSPhotoLibraryUsageDescriptionNSCameraUsageDescription添加到您的App Info.plist中,以指定访问照片库和相机的理由。有关详细信息,请参阅Cocoa键

#####Objective-C

导入

@import YangMingShan;

将代理添加到您的视图控制器

@interface YourViewController ()<YMSPhotoPickerViewControllerDelegate>

显示默认照片选择器。注意,此功能只适用于单选

[self yms_presentAlbumPhotoViewWithDelegate:self];

或使用限制photo选择10个的picker进行初始化

YMSPhotoPickerViewController *pickerViewController = [[YMSPhotoPickerViewController alloc] init];
pickerViewController.numberOfPhotoToSelect = 10;

使用自定义主题

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;

显示自定义选择器

[self yms_presentCustomAlbumPhotoView:pickerViewController delegate:self];

实现photoPickerViewControllerDidReceivePhotoAlbumAccessDenied:和photoPickerViewControllerDidReceiveCameraAccessDenied:来观察照片album和相机访问被拒绝的发生

- (void)photoPickerViewControllerDidReceivePhotoAlbumAccessDenied:(YMSPhotoPickerViewController *)picker
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Allow photo album access?", nil) message:NSLocalizedString(@"Need your permission to access photo albums", 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];
}

实现photoPickerViewController:didFinishPickingImages:,当您期望有多项照片选择时

- (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 YangMingShan

将代理添加到您的视图控制器

class YourViewController: UIViewController, YMSPhotoPickerViewControllerDelegate

显示默认照片选择器。注意,此功能只适用于单选

self.yms_presentAlbumPhotoViewWithDelegate(self)

或使用限制photo选择10个的picker进行初始化

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

使用自定义主题

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

显示自定义选择器

self.yms_presentCustomAlbumPhotoView(pickerViewController, delegate: self)

实现photoPickerViewControllerDidReceivePhotoAlbumAccessDenied(picker:)和photoPickerViewControllerDidReceiveCameraAccessDenied(picker:)来观察照片album和相机访问被拒绝的发生

func photoPickerViewControllerDidReceivePhotoAlbumAccessDenied(_ picker: YMSPhotoPickerViewController!) {
    let alertController = UIAlertController(title: "Allow photo album access?", message: "Need your permission to access photo albums", preferredStyle: .alert)
    let dismissAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
    let settingsAction = UIAlertAction(title: "Settings", style: .default) { (action) in
        UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!)
    }
    alertController.addAction(dismissAction)
    alertController.addAction(settingsAction)

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

func photoPickerViewControllerDidReceiveCameraAccessDenied(_ picker: YMSPhotoPickerViewController!) {
    let alertController = UIAlertController(title: "Allow camera album access?", message: "Need your permission to take a photo", preferredStyle: .alert)
    let dismissAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
    let settingsAction = UIAlertAction(title: "Settings", style: .default) { (action) in
        UIApplication.shared.open(URL(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.present(alertController, animated: true, completion: nil)
}

实现当您期望有多项照片选择时的photoPickerViewController(picker:didFinishPickingImages):

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
    }
}

说明

  • 示例代码已编写在YangMingShanDemo项目。您可以通过阅读代码了解如何在您的项目中实现这些功能。只需使用GitHub将YangMingShan克隆到您的本地硬盘。它应该与您的Xcode一起运行。
  • API参考文档 > 请参阅YangMingShan项目中gh-pages。我们使用appledoc来生成此文档。生成当前文档的命令行如下:
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}

许可证

此软件可以在Yahoo Inc. BSD许可证下免费使用。
有关许可证文本和版权信息,请参阅LICENSE