
代码工具
CG-L
Stay Hungry,Stay Foolish.
展开
-
工具类:快速拼接文件路径( NSString 分类)
#import <Foundation/Foundation.h>@interface NSString (Path)- (NSString *)appendDocument;- (NSString *)appendCache;- (NSString *)appendTmp;@end#import "NSString+Path.h"@implementation NSString (Path原创 2016-03-29 13:57:46 · 588 阅读 · 0 评论 -
正则判断手机、密码、邮箱
#import <Foundation/Foundation.h>@interface NSString (checkNumOrPW)//正则匹配手机号+ (BOOL)checkTelNumber:(NSString *) telNumber;//正则匹配用户密码6-20位数字、字母和下划线三选二组合+ (BOOL)checkPassword:(NSString *) password;/原创 2016-06-21 22:54:26 · 786 阅读 · 0 评论 -
按钮文字倒计时效果
// 开启倒计时效果(将此方法在按钮点击事件中执行)- (void)openCountdown { //倒计时时间 __block NSInteger time = 59; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_s原创 2016-06-21 22:59:04 · 827 阅读 · 0 评论 -
示例:在项目中写一个FMDB 的封装类
#import #import "FMDatabase.h"@interface FMDBManager : NSObject@property (nonatomic,retain)FMDatabase *dataBase;//建购物车的表- (void)createShopCarTable;//加对象- (BOOL)insertShopCar:(CGGoodsListBasic原创 2016-09-09 09:49:19 · 530 阅读 · 0 评论 -
用 PNChart 做统计图
用 cocoapod 下载图表库:pod “PNChart”#import "ViewController.h"#import "CorePlot-CocoaTouch.h"#import "PNChartDelegate.h"#import "PNChart.h"#define ARC4RANDOM_MAX 0x100000000@interface ViewController ()<P原创 2016-08-20 11:18:37 · 1963 阅读 · 0 评论 -
用 webView 加载 html 字符串代码来显示图片
核心代码句:[self.webView loadHTMLString:[NSString stringWithFormat:@"<此处填写要加载的路径或者地址>"] baseURL:nil];给 html 字符串代码添加字符,可以用替换的思想进行添加//此 html 代码中原有的语句是:“/images/upload/Image/asdfasfdasdfpic.jpg”,我们要加上“http://w原创 2016-08-20 11:27:46 · 1597 阅读 · 0 评论 -
一个带有 PlaceHolder 的BRPlaceholderTextView
#import <UIKit/UIKit.h>@interface BRPlaceholderTextView : UITextView@property(copy,nonatomic) NSString *placeholder;@property(strong,nonatomic) NSIndexPath * indexPath;//最大长度设置@property(assign,nonat原创 2016-08-10 22:02:10 · 1278 阅读 · 0 评论 -
工具类:计算距离现在的时间:刚刚/几分钟前/几小时前/几天前/几个月前/几年前
//计算距离现在的时间+ (NSString *)compareCurrentTime:(NSString *)str { //把字符串转为NSdate NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:m原创 2016-09-01 21:54:15 · 1303 阅读 · 0 评论 -
工具类:自定义 pickerView
@property (weak, nonatomic) IBOutlet UIButton *constellationBtn;@property (nonatomic,strong) UIView *pickerMainView;@property (nonatomic,strong)UIPickerView *pickerView;//自定义pickerview@property (non原创 2016-08-30 22:28:23 · 460 阅读 · 0 评论 -
实用知识:修改文字间距、行距
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String,try your best to test attributed string text"]; [str addAttribute:NSForegroundColorAttr原创 2016-08-27 08:32:07 · 760 阅读 · 0 评论 -
工具类:计算一串字符串的宽高
#import <Foundation/Foundation.h>@interface NSString (StringSize)/** *返回值是该字符串所占的大小(width, height) *font : 该字符串所用的字体(字体大小不一样,显示出来的面积也不同) *maxSize : 为限制改字体的最大宽和高(如果显示一行,则宽高都设置为MAXFLOAT, 如果显示为多行,只需将宽原创 2016-08-27 08:24:45 · 536 阅读 · 0 评论 -
工具类:压缩一张图片
#import <UIKit/UIKit.h>@interface UIImage (compressImage)//对图片尺寸进行压缩--+(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;@end#import "UIImage+compressImage.h"@implementation UIIm原创 2016-08-27 08:25:41 · 565 阅读 · 0 评论 -
工具类:自写一个简单的图片浏览器(LCGPicBrowser)
@property (nonatomic,strong) NSMutableArray *images;@property (nonatomic,strong) UIScrollView *scrollView;@property (nonatomic,strong) UILabel *countLB;#pragma mark - 点击图片放大//点击显示大图- (void)clickToB原创 2016-09-01 22:30:55 · 617 阅读 · 0 评论 -
用 Charts 绘图表框架制作统计图
集成 Charts 框架:http://www.th7.cn/Program/IOS/201610/978760.shtml 还要另外集成 Masonry 框架使用举例:折线图:@interface LineViewController ()<ChartViewDelegate>@property (nonatomic,strong) LineChartView *LineChartView;原创 2016-10-10 16:50:33 · 1982 阅读 · 0 评论 -
自定义弹框
#import <UIKit/UIKit.h>//取消按钮点击事件typedef void(^cancelBlock)();//确定按钮点击事件typedef void(^sureBlock)();@protocol MyAlterViewDelegate <NSObject>@optional- (void)clickCancelButton;- (void)clickContinueB原创 2016-06-21 22:50:44 · 451 阅读 · 0 评论 -
本地动态生成验证码
#import <UIKit/UIKit.h>@interface AuthcodeView : UIView//字符素材数组@property (strong, nonatomic) NSArray *dataArray;//验证码字符串@property (strong, nonatomic) NSMutableString *authCodeStr;@end#import "Auth原创 2016-06-21 22:49:50 · 520 阅读 · 0 评论 -
工具类:给 ImageView 类增加下载图片的功能(模仿 SDWebImage/runtime 用法1:动态添加属性)
#import @interface DownLoadImageManager : NSObject+ (instancetype)shareManager;- (void)downloadOperationWithURLString:(NSString *)URLString finish:(void(^)(UIImage *image))finsh;- (void)cancelDo原创 2016-03-31 15:58:32 · 398 阅读 · 0 评论 -
工具类:快速字典转模型(NSObject 分类/runtime 用法2:获取属性列表)
#import @interface NSObject (PropertyList)// 通过一个字典创建一个模型+ (instancetype)objWithDict:(NSDictionary *)dict;@end#import "NSObject+PropertyList.h"#import @implementation NSObject (PropertyLis原创 2016-03-31 16:04:41 · 471 阅读 · 0 评论 -
工具类:防止数组越界崩溃问题(NSArray 分类/runtime 用法3:交换方法)
#import @interface NSArray (Safe)@end#import "NSArray+Safe.h"#import @implementation NSArray (Safe)//这个方法无论如何都会执行+ (void)load { // 选择器 SEL safeSel = @selector(safeObjectAtIndex:);原创 2016-03-31 16:07:52 · 4134 阅读 · 1 评论 -
工具类:快速获取控件 frame 值(UIView 分类)
快速获取控件 frame 值原创 2016-03-21 23:32:27 · 776 阅读 · 0 评论 -
工具类:拉伸一张图片(UIImage分类)
.h@interface UIImage (XXXXExp)/** * 拉伸图片 * * @return 返回拉伸后的图片 */- (UIImage *)stretchableImage;@end.m@implementation UIImage (XXXXExp)- (UIImage *)stretchableImage {// 只要点不在圆角范围就可以 return原创 2016-03-21 23:44:39 · 379 阅读 · 0 评论 -
工具类:快速加载 xib(UIView 分类)
.h#import <UIKit/UIKit.h>@interface UIView (CZXib)+ (instancetype)viewFromXib;+ (instancetype)viewFromXibName:(NSString *)name;@end.m#import "UIView+CZXib.h"@implementation UIView (CZXib)+ (instance原创 2016-03-21 23:51:14 · 633 阅读 · 0 评论 -
工具类:在 PCH 文件中宏定义一个取色方法
#define CZColor(r,g,b,a) [UIColor colorWithRed:r / 255.0 green:g / 255.0 blue:b / 255.0 alpha:a]原创 2016-03-22 15:41:13 · 1742 阅读 · 0 评论 -
工具类:快速创建单例
#import "CZTool.h"#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading th原创 2016-04-05 16:12:42 · 650 阅读 · 0 评论 -
工具类:控制台将 UTF8格式输出成中文
#import <Foundation/Foundation.h>@interface NSObject (Log)@end@interface NSArray (Log)@end@interface NSDictionary (Log)@end#import <UIKit/UIKit.h>#import "NSObject+Log.h"#import <objc/runtime.h>@原创 2016-04-12 22:33:01 · 365 阅读 · 0 评论 -
工具类:Base64快速加密
#import <Foundation/Foundation.h>@interface NSString (Base64)// 加密- (NSString *)base64Encode;// 解密- (NSString *)base64Decode;@end#import "NSString+Base64.h"@implementation NSString (Base64)// 对文本进原创 2016-04-13 08:43:42 · 374 阅读 · 0 评论 -
工具类:md5快速加密
#import <Foundation/Foundation.h>@interface NSString (Hash)#pragma mark - 散列函数/** * 计算MD5散列结果 * * 终端测试命令: * @code * md5 -s "string" * @endcode * * <p>提示:随着 MD5 碰撞生成器的出现,MD5 算法不应被用于任何软件完整原创 2016-04-13 09:31:48 · 375 阅读 · 0 评论 -
工具类:正则表达式工具类
#import <Foundation/Foundation.h>@interface NSString (RegularExpression)/** * 匹配第一个符合正则语法的结果, 返回匹配的结果(字符串) * * @param pattern 正则语法 * * @return 返回第一个匹配的字符串, 如果没有则返回nil */- (NSString *)firstMat原创 2016-05-12 08:33:46 · 695 阅读 · 0 评论 -
自定义 Switch 开关按钮
#import <UIKit/UIKit.h>@interface SevenSwitch : UIControl@property (nonatomic, assign) BOOL on;@property (nonatomic, strong) UIColor *inactiveColor;@property (nonatomic, strong) UIColor *activeColo原创 2016-06-21 22:48:05 · 1640 阅读 · 0 评论 -
再次封装 AFNetworking
#import <Foundation/Foundation.h>#import "AFNetworking.h"typedef void(^NetworkingSuccess)(id response);typedef void(^NetworkingFail)(NSError *error);@interface NetworkingTools : NSObject+ (void)post原创 2017-01-09 22:17:24 · 517 阅读 · 0 评论