Skip to content

Commit

Permalink
add Some uikit annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakey committed Sep 12, 2015
1 parent 22ce76f commit 65dc980
Show file tree
Hide file tree
Showing 65 changed files with 782 additions and 71 deletions.
5 changes: 5 additions & 0 deletions Categories/UIKit/UIBezierPath/UIBezierPath+SVG.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
#import <UIKit/UIKit.h>

@interface UIBezierPath (SVG)
/**
* @brief UIBezierPath转成SVG
*
* @return SVG
*/
- (NSString*)toSVGString;
@end
5 changes: 5 additions & 0 deletions Categories/UIKit/UIBezierPath/UIBezierPath+SVG.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#import "UIBezierPath+SVG.h"
static void SVGApplier(void* info, const CGPathElement* element);
@implementation UIBezierPath (ZTKit)
/**
* @brief UIBezierPath转成SVG
*
* @return SVG
*/
- (NSString*)toSVGString
{
CGPathRef path = [self CGPath];
Expand Down
7 changes: 6 additions & 1 deletion Categories/UIKit/UIButton/UIButton+BackgroundColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#import <UIKit/UIKit.h>

@interface UIButton (BackgroundColor)

/**
* @brief 使用颜色设置按钮背景
*
* @param backgroundColor 背景颜色
* @param state 按钮状态
*/
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state;
@end
7 changes: 6 additions & 1 deletion Categories/UIKit/UIButton/UIButton+BackgroundColor.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
#import "UIButton+BackgroundColor.h"

@implementation UIButton (BackgroundColor)

/**
* @brief 使用颜色设置按钮背景
*
* @param backgroundColor 背景颜色
* @param state 按钮状态
*/
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state
{
[self setBackgroundImage:[UIButton imageWithColor:backgroundColor] forState:state];
Expand Down
4 changes: 3 additions & 1 deletion Categories/UIKit/UIButton/UIButton+TouchAreaInsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#import <UIKit/UIKit.h>

@interface UIButton (JLUtils)

/**
* @brief 设置按钮额外热区
*/
@property (nonatomic, assign) UIEdgeInsets touchAreaInsets;

@end
4 changes: 3 additions & 1 deletion Categories/UIKit/UIButton/UIButton+TouchAreaInsets.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ - (UIEdgeInsets)touchAreaInsets
{
return [objc_getAssociatedObject(self, @selector(touchAreaInsets)) UIEdgeInsetsValue];
}

/**
* @brief 设置按钮额外热区
*/
- (void)setTouchAreaInsets:(UIEdgeInsets)touchAreaInsets
{
NSValue *value = [NSValue valueWithUIEdgeInsets:touchAreaInsets];
Expand Down
10 changes: 9 additions & 1 deletion Categories/UIKit/UIColor/UIColor+Gradient.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
#import <UIKit/UIKit.h>

@interface UIColor (Gradient)
//渐变
/**
* @brief 渐变颜色
*
* @param c1 开始颜色
* @param c2 结束颜色
* @param height 渐变高度
*
* @return 渐变颜色
*/
+ (UIColor*)gradientFromColor:(UIColor*)c1 toColor:(UIColor*)c2 withHeight:(int)height;
@end
10 changes: 9 additions & 1 deletion Categories/UIKit/UIColor/UIColor+Gradient.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
@implementation UIColor (Gradient)

#pragma mark - Gradient Color

/**
* @brief 渐变颜色
*
* @param c1 开始颜色
* @param c2 结束颜色
* @param height 渐变高度
*
* @return 渐变颜色
*/
+ (UIColor*)gradientFromColor:(UIColor*)c1 toColor:(UIColor*)c2 withHeight:(int)height
{
CGSize size = CGSizeMake(1, height);
Expand Down
5 changes: 5 additions & 0 deletions Categories/UIKit/UIColor/UIColor+Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
#import <UIKit/UIKit.h>

@interface UIColor (Random)
/**
* @brief 随机颜色
*
* @return UIColor
*/
+ (UIColor *)RandomColor;
@end
12 changes: 10 additions & 2 deletions Categories/UIKit/UIColor/UIColor+Web.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
#import <UIKit/UIKit.h>

@interface UIColor (Web)
// 获取canvas用的颜色字符串
/**
* @brief 获取canvas用的颜色字符串
*
* @return canvas颜色
*/
- (NSString *)canvasColorString;
//获取网页颜色字串
/**
* @brief 获取网页颜色字串
*
* @return 网页颜色
*/
- (NSString *)webColorString;
@end
12 changes: 10 additions & 2 deletions Categories/UIKit/UIColor/UIColor+Web.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
#import "UIColor+Web.h"

@implementation UIColor (Web)
/// 获取canvas用的颜色字符串
/**
* @brief 获取canvas用的颜色字符串
*
* @return canvas颜色
*/
- (NSString *)canvasColorString
{
CGFloat *arrRGBA = [self getRGB];
Expand All @@ -19,7 +23,11 @@ - (NSString *)canvasColorString
float a = arrRGBA[3];
return [NSString stringWithFormat:@"rgba(%d,%d,%d,%f)", r, g, b, a];
}
/// 获取网页颜色字串
/**
* @brief 获取网页颜色字串
*
* @return 网页颜色
*/
- (NSString *)webColorString
{
CGFloat *arrRGBA = [self getRGB];
Expand Down
24 changes: 23 additions & 1 deletion Categories/UIKit/UIImage/UIImage+Alpha.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,34 @@
#import <UIKit/UIKit.h>

@interface UIImage (Alpha)
/**
* @brief 是否有alpha通道
*
* @return 是否有alpha通道
*/
- (BOOL)hasAlpha;
/**
* @brief 如果没有alpha通道 增加alpha通道
*
* @return 如果没有alpha通道 增加alpha通道
*/
- (UIImage *)imageWithAlpha;
/**
* @brief 增加透明边框
*
* @param borderSize 边框尺寸
*
* @return 增加透明边框后的图片
*/
- (UIImage *)transparentBorderImage:(NSUInteger)borderSize;

//裁切含透明图片为最小大小

//http://stackoverflow.com/questions/6521987/crop-uiimage-to-alpha?answertab=oldest#tab-top
/**
* @brief 裁切含透明图片为最小大小
*
* @return 裁切后的图片
*/
- (UIImage *)trimmedBetterSize;

@end
27 changes: 22 additions & 5 deletions Categories/UIKit/UIImage/UIImage+Alpha.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ - (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size;
@end

@implementation UIImage (Alpha)

// Returns true if the image has an alpha layer
/**
* @brief 是否有alpha通道
*
* @return 是否有alpha通道
*/
- (BOOL)hasAlpha {
CGImageAlphaInfo alpha = CGImageGetAlphaInfo(self.CGImage);
return (alpha == kCGImageAlphaFirst ||
alpha == kCGImageAlphaLast ||
alpha == kCGImageAlphaPremultipliedFirst ||
alpha == kCGImageAlphaPremultipliedLast);
}

// Returns a copy of the given image, adding an alpha channel if it doesn't already have one
/**
* @brief 如果没有alpha通道 增加alpha通道
*
* @return 如果没有alpha通道 增加alpha通道
*/
- (UIImage *)imageWithAlpha {
if ([self hasAlpha]) {
return self;
Expand Down Expand Up @@ -54,6 +60,13 @@ - (UIImage *)imageWithAlpha {

// Returns a copy of the image with a transparent border of the given size added around its edges.
// If the image has no alpha layer, one will be added to it.
/**
* @brief 增加透明边框
*
* @param borderSize 边框尺寸
*
* @return 增加透明边框后的图片
*/
- (UIImage *)transparentBorderImage:(NSUInteger)borderSize {
// If the image does not have an alpha layer, add one
UIImage *image = [self imageWithAlpha];
Expand Down Expand Up @@ -87,7 +100,11 @@ - (UIImage *)transparentBorderImage:(NSUInteger)borderSize {

return transparentBorderImage;
}

/**
* @brief 裁切含透明图片为最小大小
*
* @return 裁切后的图片
*/
- (UIImage *)trimmedBetterSize {

CGImageRef inImage = self.CGImage;
Expand Down
8 changes: 7 additions & 1 deletion Categories/UIKit/UIImage/UIImage+Capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
#import <UIKit/UIKit.h>

@interface UIImage (Capture)

/**
* @brief 截图指定view成图片
*
* @param view 一个view
*
* @return 图片
*/
+ (UIImage *)captureWithView:(UIView *)view;

///截图(未测试是否可行)
Expand Down
7 changes: 7 additions & 0 deletions Categories/UIKit/UIImage/UIImage+Capture.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
#import "UIImage+Capture.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIImage (Capture)
/**
* @brief 截图指定view成图片
*
* @param view 一个view
*
* @return 图片
*/
+ (UIImage *)captureWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [UIScreen mainScreen].scale);
Expand Down
35 changes: 33 additions & 2 deletions Categories/UIKit/UIImage/UIImage+Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,45 @@
#import <UIKit/UIKit.h>

@interface UIImage (Color)
/**
* @brief 根据颜色生成纯色图片
*
* @param color 颜色
*
* @return 纯色图片
*/
+ (UIImage *)imageWithColor:(UIColor *)color;
/**
* @brief 取图片某一点的颜色
*
* @param point 某一点
*
* @return 颜色
*/
- (UIColor *)colorAtPoint:(CGPoint )point;
//more accurate method ,colorAtPixel 1x1 pixel
/**
* @brief 取某一像素的颜色
*
* @param point 一像素
*
* @return 颜色
*/
- (UIColor *)colorAtPixel:(CGPoint)point;
//返回该图片是否有透明度通道
/**
* @brief 返回该图片是否有透明度通道
*
* @return 是否有透明度通道
*/
- (BOOL)hasAlphaChannel;

///获得灰度图
/**
* @brief 获得灰度图
*
* @param sourceImage 图片
*
* @return 获得灰度图片
*/
+ (UIImage*)covertToGrayImageFromImage:(UIImage*)sourceImage;

@end
36 changes: 34 additions & 2 deletions Categories/UIKit/UIImage/UIImage+Color.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
#import "UIImage+Color.h"

@implementation UIImage (Color)
/**
* @brief 根据颜色生成纯色图片
*
* @param color 颜色
*
* @return 纯色图片
*/
+ (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
Expand All @@ -22,6 +29,13 @@ + (UIImage *)imageWithColor:(UIColor *)color {

return image;
}
/**
* @brief 取图片某一点的颜色
*
* @param point 某一点
*
* @return 颜色
*/
- (UIColor *)colorAtPoint:(CGPoint )point
{
if (point.x < 0 || point.y < 0) return nil;
Expand Down Expand Up @@ -65,6 +79,13 @@ - (UIColor *)colorAtPoint:(CGPoint )point
free(rawData);
return result;
}
/**
* @brief 取某一像素的颜色
*
* @param point 一像素
*
* @return 颜色
*/
- (UIColor *)colorAtPixel:(CGPoint)point
{
// Cancel if point is outside image coordinates
Expand Down Expand Up @@ -106,7 +127,11 @@ - (UIColor *)colorAtPixel:(CGPoint)point
CGFloat alpha = (CGFloat)pixelData[3] / 255.0f;
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}

/**
* @brief 返回该图片是否有透明度通道
*
* @return 是否有透明度通道
*/
- (BOOL)hasAlphaChannel
{
CGImageAlphaInfo alpha = CGImageGetAlphaInfo(self.CGImage);
Expand All @@ -116,7 +141,14 @@ - (BOOL)hasAlphaChannel
alpha == kCGImageAlphaPremultipliedLast);
}

//转成黑白图像
/**
* @brief 获得灰度图
*
* @param sourceImage 图片
*
* @return 获得灰度图片
*/

+ (UIImage*)covertToGrayImageFromImage:(UIImage*)sourceImage
{
int width = sourceImage.size.width;
Expand Down
Loading

0 comments on commit 65dc980

Please sign in to comment.