MCUIImageAdvanced 0.2.7

MCUIImageAdvanced 0.2.7

测试已测试
语言语言 Obj-CObjective C
许可证 BSD 3.0
发布最后发布2016年11月

MiregoMarc LefrancoisFrancois Lambert 维护。



  • Mirego,Inc.

MCUIImageAdvanced - UIImage 高级功能

UIImage 提供实用方法。

使用

动画

创建用于 UIImageViewsetAnimationImages: 动画的 UIImage 数组的简单方法。

#import 'UIImage+MCAdvanced.h'

- (void)funWithAnimations
{
  // UIImage array animations to use with the UIImageView setAnimationImages:
  // expects file name to be numbered sequentialy.
  NSArray* animationImages = [UIImage animationImagesWithPrefix:@"funWithAnimations" imageQuantity:24];
  // [funWithAnimations0.png, funWithAnimations1.png, funWithAnimations2,png, ... funWithAnimations23.png]

  // Save as above put resizes the images as specified. Use CGSizeZero for original size
  NSArray* small = [UIImage animationImagesWithPrefix:@"funWithAnimations" imageQuantity:24 resizeImages:CGSizeMake(44,44)];

  // Save as the first one but specify the number format
  NSArray* zeroPrefixed = [UIImage animationImagesWithPrefix:@"funWithAnimations" imageQuantity:24 resizeImages:CGSizeZero mask:@"%02u"];
  // [funWithAnimations00.png, funWithAnimations01.png, funWithAnimations02,png, ... funWithAnimations23.png]

  // Same as the first one but starting at 1
  NSArray*  = [UIImage animationImagesWithPrefix:@"funWithAnimations" imageQuantity:24 resizeImages:CGSizeZero mask:@"%u" startingIndex:1];
  // [funWithAnimations1.png, funWithAnimations2.png, funWithAnimations3,png, ... funWithAnimations24.png]
}

混合图像和颜色

通过不同的 CGBlendMode 来混合 UIImageUIColor

#import 'UIImage+MCAdvanced.h'

- (void)funWithBlending
{

  // Blend images
  // layers: NSArray of UIColor and/or UIImage (the last item is the top most layer).
  UIImage *blendedImage = [UIImage blendedImageWithImage:srcImage
                                                  layers:@[[UIColor colorWithWhite:1.0 alpha:0.2]]
                                               blendMode:kCGBlendModeNormal;

  // Same as above bug using different blendModes for each layer.
  UIImage *blendedImage = [UIImage blendedImageWithImage:srcImage
                                                  layers:@[[UIColor colorWithWhite:1.0 alpha:0.2],[UIColor colorWithWhite:0.2 alpha:0.2]]
                                              blendModes:@[@(kCGBlendModeLuminosity),@(kCGBlendModeDarken)]
                                        defaultBlendMode:kCGBlendModeNormal];

  // Render a blended image in a specific CGContext
  UIImage *blendedImage = [UIImage blendedImageInContext:ctx
                                                withRect:CGSizeMake(CGBitmapContextGetWidth(ctx),CGBitmapContextGetHeight(ctx))
                                                   image:srcImage
                                                  layers:@[[UIColor colorWithWhite:1.0 alpha:0.2]]
                                              blendModes:nil
                                        defaultBlendMode:kCGBlendModeNormal];
}

生成简单图像

使用 CoreGraphics 绘制获得的简单 UIImage

#import 'UIImage+MCAdvanced.h'

- (void)funWithImageGeneration
{
  // Square opaque image
  UIImage *redSquareImage = [UIImage mc_generateImageOfSize:CGSizeMake(100,100) color:[UIColor redcolor]];

  // Square translucent image
  UIImage *redTranslucentSquareImage = [UIImage mc_generateImageOfSize:CGSizeMake(100,100) color:[[UIColor redcolor] colorWithAlphaComponent:0.5f] opaque:NO];

  // Circle image
  UIImage *redCircleImage = [UIImage mc_generateCircleImageOfSize:CGSize(100,100) color:[UIColor redcolor]];  
}

retina 和非视网膜图像 (@2x)

仅保留 @2x 资源以使您的应用程序更小。视网膜图像将调用并加载 @2x 版本,并生成标凈定义。如果需要,将其保留在内存缓存中以提升性能。

- (void)funWithRetinaImages
{
  // Load [email protected]
  UIImage* img = [UIImage imageNamedRetina:@"funWithRetinaImage.png"];

  // Force loading the image from flash every time.
  UIImage* img = [UIImage imageNamedRetina:@"funWithRetinaImage.png" useMemoryCache:NO];

  // Load the image with the proper resolution and tint it.
  UIImage* img = [UIImage imageNamedRetina:@"funWithRetinaImage.png" tintColor:[UIColor colorWithWhite:1.0 alpha:0.2]]

  // Load an image from disk and tint it using a specific blendmode
  UIImage* img = [UIImage imageNamedRetina:@"funWithRetinaImage.png" tintColor:[UIColor colorWithWhite:1.0 alpha:0.2] overlayBlendMode:kCGBlendModeOverlay];

  // Load an image from disk and tint it using another image and, if needed,
  // with a shadow using an image too (use nil if not needed).
  UIImage* img = [UIImage imageNamedRetina:@"funWithRetinaImage.png" tintColor:[UIColor colorWithWhite:1.0 alpha:0.2] overlayName:@"overlay.png" shadowName:nil];

  // Pre-shrink all @2x image in the resources in the background.
  // `progressBlock` will be called with index and count set to -1 if nothing
  // is to be done (no need to warmup images).
  UIImage* img = [UIImage imageNamedRetinaWarmupWithProgressBlock:(void (^)(NSString* imageName, NSUInteger index, NSUInteger count))progressBlock];
}

添加到您的项目

如果您正在使用 CocoaPods,这是一种非常简单的方法。将以下内容添加到您的 Podfile 中,并运行 pod install

pod 'MCUIImageAdvanced', :git => 'https://github.com/mirego/MCUIImageAdvanced.git'

不要忘记在需要的地方导入 #import "UIImage+MCAdvanced.h"

许可证

MCUIImageAdvanced 是 © 2013 Mirego 的作品,并且可以在 新 BSD 许可证下自由分发。请参阅 LICENSE.md 文件。

关于 Mirego

Mirego 是一支充满热情的人组成的团队,他们相信工作是一个可以创新和娱乐的地方。我们是一支由 才华横溢的人 组成的团队,他们想象并构建美丽的 Web 和移动应用程序。我们聚集在一起分享想法和 改变世界

我们还 热爱开源软件,并尽力回馈社区。