ZPCategory
目錄
- 宏文件
- NSString
- NSDate
- NSTimer
- NSDictionary
- UITextField
- UITextView
- UIButton
- UIImage
- UIViewController
宏文件
這個(gè)文件中主要有以下幾個(gè)功能:
- 開發(fā)環(huán)境和正式環(huán)境的配置埃叭;
- 項(xiàng)目中集成的第三方的配置;
- RGB顏色;
- 弱引用self奈应;
- 屏幕寬&高碍现;
- 狀態(tài)欄&Tabbar&SafeArea的數(shù)值伤疙;
- 設(shè)備的判斷唬渗;
NSString
字符串寬度&&高度
1.根據(jù)字體&高度值依,獲取字符串的寬度(沒有行高)
- (float)widthWithFont:(UIFont *)font height:(float)height;
2.根據(jù)字體&寬度肯骇,獲取字符串的高度(沒有行高)
- (float)heightWithFont:(UIFont *)font width:(float)width;
3.根據(jù)字體&寬度&行高窥浪,獲取字符串改的高度祖很;
- (float)heightWithFont:(UIFont *)font width:(float)width lineSpacing:(float)lineSpacing;
4.根據(jù)字體&寬度&行高,獲取字符串的Size漾脂;
- (CGSize)sizeWithFont:(UIFont *)font width:(float)width lineSpacing:(float)lineSpacing;
字符串 正則表達(dá)式
1.判斷是不是手機(jī)號(hào)
- (BOOL)isValidateMobile;
2.判斷是不是固定電話
- (BOOL)isValidatePhone;
3.判斷是不是客服電話
- (BOOL)is400Phone;
4.判斷是不是身份證
- (BOOL)isIdCard;
數(shù)據(jù)類型額判斷
1.是否是正整數(shù)
- (BOOL)isPositiveInteger;
2.是否是浮點(diǎn)數(shù)
- (BOOL)isFloat;
3.檢查輸入字符串是否只由英文字母和數(shù)字組成
- (BOOL)isNumberOrLetter;
4.檢查輸入字符串是否只由漢字和英文字母組成
- (BOOL)isChineseOrLetter;
5.是否為空字符串
- (BOOL)isBlankString;
NSString->NSAttributedString
1.NSString->NSAttributedString 帶有行高屬性
- (NSAttributedString *)toAttributeStringWithLineSpacing:(float)lineSpacing;
字符串加密
1.MD5
- (NSString *)md5;
2.SHA1
- (NSString *)SHA1;
字符串過濾
1.去除兩端空格和回車
- (NSString *)trim;
2.僅去除兩端空格
- (NSString *)trimOnlyWhitespace;
3.去除html格式
+ (NSString *)filterHtml:(NSString *)html;
根據(jù)圖片名字返回圖片
1.根據(jù)圖片名字返回圖片
- (UIImage *)toImage;
NSDate
1.NSDate -> NSString
- (NSString *)formatString:(NSString *)dateFormat;
2.根據(jù)unix時(shí)間戳構(gòu)造NSDate
+ (NSDate *)dateWithUnixTime:(double)unixtime;
3.將時(shí)間轉(zhuǎn)化為0秒模式
+ (NSDate *)changeDateToZeroMinutDate:(NSDate *)date;
4.獲得指定月份的第一天和最后一天
+ (NSArray *)getFirstAndLastDayOfThisMonthWithNsDate:(NSDate *)date;
NSTimer
1.用block的方式穿件定時(shí)器
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)timeInterval block:(void (^)(void))block repeat:(BOOL)repeat;
NSDictionary
數(shù)據(jù)類型的Get
1.設(shè)置一個(gè)BOOL值
- (BOOL)boolForKey:(NSString *)key;
2.設(shè)置一個(gè)NSInteger值
- (NSInteger)integerForKey:(NSString *)key;
3.設(shè)置一個(gè)int值
- (int)intForKey:(NSString *)key;
4.設(shè)置一個(gè)double值
- (double)doubleForKey:(NSString *)key;
5.設(shè)置一個(gè)float值
- (float)floatForKey:(NSString *)key;
6.設(shè)置一個(gè)long long值
- (long long)longLongForKey:(NSString *)key;
7.設(shè)置一個(gè)unsigned long long值
- (unsigned long long)unsignedLongLongForKey:(NSString *)key;
8.設(shè)置一個(gè)NSString值
- (NSString *)stringForKey:(NSString *)key;
9.設(shè)置一個(gè)NSArray值
- (NSArray *)arrayForKey:(NSString *)key;
10.value為空時(shí)假颇,不set此key
- (void)safeValue:(id)value forKey:(NSString *)key;
UITextField
最大長(zhǎng)度和只可以輸入數(shù)字的屬性添加
/**
最大長(zhǎng)度
*/
@property (nonatomic, assign) NSInteger maxLength;
/**
是否只可以輸入數(shù)字
*/
@property (nonatomic, assign) BOOL canOnlyInputNumber;
LeftView
1.設(shè)置leftview為圖片
/**
* 設(shè)置leftview為圖片
*
* @param imageName 圖片名稱
*/
- (void)setLeftViewWithImageName:(NSString *)imageName;
2.設(shè)置leftView為文字
/**
* 設(shè)置leftView為文字
*
*/
- (void)setLeftViewWithText:(NSString *)text;
3.設(shè)置leftView為文字
/**
* 設(shè)置leftView為文字
*
* @param text 文字
* @param minWidth 最小寬度
*/
- (void)setLeftViewWithText:(NSString *)text minWidth:(CGFloat)minWidth;
4.設(shè)置leftView為文字
/**
* 設(shè)置leftView為文字
*
* @param text 文字
* @param minWidth 最小寬度
* @param color 占位文字顏色
*/
- (void)setLeftViewWithText:(NSString *)text minWidth:(CGFloat)minWidth color:(UIColor *)color;
RightView
1.設(shè)置rightView為文字
/**
* 設(shè)置rightView為文字
*
* @param text 文字
*/
- (void)setRightViewWithText:(NSString *)text;
2.設(shè)置rightView為圖片
/**
* 設(shè)置rightView為圖片
*
* @param imageName 圖片名稱
*/
- (void)setRightViewWithImageName:(NSString *)imageName;
3.設(shè)置rightView為button
/**
* 設(shè)置rightView為button
*
* @param imageName 圖片名稱
*/
- (void)setRightViewButtonWithImageName:(NSString *)imageName taget:(id)taget selector:(SEL)selector;
Padding
1.設(shè)置UITextField左側(cè)內(nèi)邊距
/**
* 設(shè)置UITextField左側(cè)內(nèi)邊距
*
* @param padding 距離
*/
- (void)setPaddingLeftSpace:(float)padding;
2.設(shè)置UITextField右側(cè)內(nèi)邊距
/**
* 設(shè)置UITextField右側(cè)內(nèi)邊距
*
* @param padding 距離
*/
- (void)setPaddingRightSpace:(float)padding;
UI顯示
1.設(shè)置底部邊框
/**
* 設(shè)置底部邊框
*
* @param lineColor 邊框顏色
*/
- (void)setBottomBorderLineWithColor:(UIColor *)lineColor;
2.設(shè)置placeholder的顏色
/**
* 設(shè)置placeholder的顏色
*
*/
- (void)setPlaceholderColor:(UIColor *)color;
3.設(shè)置下劃線出去左邊的文字
/**
* 設(shè)置下劃線出去左邊的文字
*/
- (void)setLeftViewWithText:(NSString *)text minWidth:(CGFloat)minWidth withOutTextBottomLineColor:(UIColor *)color;
UITextView
增加 placeHolder & placeHolderFont 屬性
@property (nonatomic, copy) NSString *placeHolder;
@property (nonatomic, strong) UIFont *placeHolderFont;
UButton
點(diǎn)擊方式換成block方式
/**
* UIButton+Block
*
* @param controlEvent 觸摸事件
* @param action 執(zhí)行的方法
*/
- (void)handleControlEvent:(UIControlEvents)controlEvent withBlock:(ActionBlock)action;
UIImage
返回相片的主要顏色
/**
返回相片的主要顏色
@param image 圖片
@return 返回的顏色色值
*/
+ (UIColor*)mostColor:(UIImage *)image;
UIViewController
NavigationBar
1.設(shè)置左側(cè)Navigationbar為“返回”(使用backBarButtonItem)
/**
* 設(shè)置左側(cè)Navigationbar為“返回”(使用backBarButtonItem)
*/
- (void)setLeftNavigationBarToBack;
2.設(shè)置左側(cè)Navigationbar為“返回”(使用leftbarbutton)
/**
* 設(shè)置左側(cè)Navigationbar為“返回”(使用leftbarbutton)
*
* @param block 點(diǎn)擊時(shí)執(zhí)行的block代碼
*/
- (void)setLeftNavigationBarToBackWithBlock:(void (^)(void))block;
3.為左側(cè)后退Navigationbar增加確認(rèn)提示框
/**
* 為左側(cè)后退Navigationbar增加確認(rèn)提示框
*/
- (void)setLeftNavigationBarToBackWithConfirmDialog;
4.設(shè)置NavigationBar(文字)
/**
* 設(shè)置NavigationBar(文字)
*
* @param position 位置
* @param text 文字
* @param block 點(diǎn)擊后執(zhí)行的代碼
*/
- (void)setNavigationBar:(NavigationBarPosition)position withText:(NSString *)text touched:(void (^)(void))block;
5.設(shè)置NavigationBar(圖片)
/**
* 設(shè)置NavigationBar(圖片)
*
* @param position 位置
* @param imageName 圖片名稱
* @param block 點(diǎn)擊后執(zhí)行的代碼
*/
- (void)setNavigationBar:(NavigationBarPosition)position withImageName:(NSString *)imageName touched:(void (^)(void))block;
6.設(shè)置NavigationBar(圖片)
/**
* 設(shè)置NavigationBar(圖片)
*
* @param position 位置
* @param imageName 圖片名稱
* @param block 點(diǎn)擊后執(zhí)行的代碼
*/
- (void)setNavigationBar:(NavigationBarPosition)position withImageName:(NSString *)imageName spacing:(NSInteger)spacing touched:(void (^)(void))block;
7.設(shè)置NavigationBar(文字)
/**
* 設(shè)置NavigationBar(文字)
*
* @param position 位置
* @param text 文字
* @param color 文字顏色
* @param block 點(diǎn)擊后執(zhí)行的代碼
*/
- (void)setNavigationBar:(NavigationBarPosition)position withText:(NSString *)text withColor:(UIColor *)color touched:(void (^)(void))block;
8.設(shè)置NavigationBar(文字)
/**
* 設(shè)置NavigationBar(文字)
*
* @param position 位置
* @param text 文字
* @param color 文字顏色
* @param font 字體
* @param block 點(diǎn)擊后執(zhí)行的代碼
*/
- (void)setNavigationBar:(NavigationBarPosition)position withText:(NSString *)text withColor:(UIColor *)color withFont:(UIFont *)font touched:(void (^)(void))block;
9.設(shè)置NavigationBar隱藏或顯示
/**
* 設(shè)置NavigationBar隱藏或顯示
*
* @param position 位置
* @param hidden YES:隱藏 NO:顯示
*/
- (void)hiddenNavigationBar:(NavigationBarPosition)position hidden:(BOOL)hidden;
10.跳轉(zhuǎn)到指定的ViewController
/**
* 跳轉(zhuǎn)到指定的ViewController
*
* @param viewControllerClass 控制器類型
*/
- (void)popToViewController:(Class)viewControllerClass;
11.NavigationController里上一個(gè)ViewController
/**
* NavigationController里上一個(gè)ViewController
*
*/
- (UIViewController *)previosViewController;
12.移除當(dāng)前NavigationController里ViewController的上一個(gè)ViewController
/**
* 移除當(dāng)前NavigationController里ViewController的上一個(gè)ViewController
*/
- (void)removePreviosViewControllerInNavigationControllers;
13.添加多個(gè)按鈕時(shí)
/**
* 添加多個(gè)按鈕時(shí)
*
* @param position 位置
* @param array buttonImageNameAndButtonTypeArray
* @param target 目標(biāo)
* @param selector 響應(yīng)方法
*/
- (void)setNavigationBar:(NavigationBarPosition)position withImageNameAndButtonTypeArray:(NSArray *)array target:(id)target selectors:(SEL)selector;
14.移除navigationbutton
/**
* 移除navigationbutton
*
* @param position 位置
*/
- (void)removeNavigationBarBar:(NavigationBarPosition)position;
StoryBoard
1.從storyboard中初始化ViewController
/**
* 從storyboard中初始化ViewController
*
* @param storyBoardName storyboard名稱
* @param identifier ViewController標(biāo)識(shí)符
*
* @return ViewController實(shí)例
*/
+ (instancetype)viewControllerFromStoryBoard:(NSString *)storyBoardName withIdentifier:(NSString *)identifier;