OC-UIKit扩展

NSString扩展


.h中-需要pod 'CocoaSecurity'

@interface NSString(extend)

- (NSString *)md5;/*md5加密*/

- (NSString*)base64_encode;/*base64加密*/

- (NSString*)base64_decode;/*base64解密*/

+ (NSString*)app_version;/*当前app版本*/

+ (NSString *)stringWithDate:(NSDate *)date dateFormat:(NSString *)dateFormat;/*将日期转化成字符串*/

+ (NSString *)className:(Class)_class;/*将类名转换成字符串*/

+ (NSString *)strWithDoubNum:(double)doubleNumber;/*统一项目中小数的位数*/

@end

.m中

@implementation NSString (extend)

- (NSString *)md5

{

CocoaSecurityResult* e = [CocoaSecurity md5:self];

return e.hexLower;

}

- (NSString *)base64_encode

{

NSData* data = [self dataUsingEncoding:NSUTF8StringEncoding];

CocoaSecurityEncoder* e = [[CocoaSecurityEncoder alloc] init];

return [e base64:data];

}

- (NSString *)base64_decode

{

CocoaSecurityDecoder* e = [[CocoaSecurityDecoder alloc] init];

NSString* ret = [[NSString alloc] initWithData:[e base64:self] encoding:NSUTF8StringEncoding];

return ret;

}

+ (NSString *)app_version

{

NSDictionary *info = [[NSBundle mainBundle] infoDictionary];

NSString *version = [info objectForKey:@"CFBundleShortVersionString"];

//NSLog(@"appver:%@",version);

return version;

}

+ (NSString *)stringWithDate:(NSDate *)date dateFormat:(NSString *)dateFormat

{

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateFormat:dateFormat];

return [formatter stringFromDate:date];

}

+ (NSString *)className:(Class)_class

{

return [NSString stringWithUTF8String:object_getClassName(_class)];

}

+ (NSString *)strWithDoubNum:(double)doubleNumber

{

return [NSString stringWithFormat:@"%.02lf",doubleNumber];

}

@end

UIImage扩展-改变image填充色


.h中-通过代码改变imag的填充色

@interface UIImage (extend)

- (UIImage *)imageWithTintColor:(UIColor *)tintColor;

- (UIImage *)imageWithGradientTintColor:(UIColor *)tintColor;

@end

.m中

- (UIImage *)imageWithTintColor:(UIColor *)tintColor

{

return [self imageWithTintColor:tintColor blendMode:kCGBlendModeDestinationIn];

}

- (UIImage *)imageWithGradientTintColor:(UIColor *)tintColor

{

return [self imageWithTintColor:tintColor blendMode:kCGBlendModeOverlay];

}

- (UIImage *)imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode

{

UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);

[tintColor setFill];

CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);

UIRectFill(bounds);

[self drawInRect:bounds blendMode:blendMode alpha:1.0f];

if (blendMode != kCGBlendModeDestinationIn) {

[self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];

}

UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return tintedImage;

}

NSDate扩展-将字符串变为NSDate


.h中

@interface NSDate (extend)

+ (NSDate *)dateWithString:(NSString *)string dateFormat:(NSString *)dateFormat;

@end

.m中

@implementation NSDate (extend)

+ (NSDate *)dateWithString:(NSString *)string dateFormat:(NSString *)dateFormat

{

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateFormat:dateFormat];

return [formatter dateFromString:string];

}

@end

你可能感兴趣的:(OC-UIKit扩展)