ios開發總結:Utils經常使用方法等收集,添加擴展類,工具類方法,擁有不少方便快捷功能(不斷更新中。。。)

BOBUtils 工具大全

本人github開源和收集功能地址:https://github.com/niexiaoboios

 

【對ios新手或者工做一年之內開發人員頗有用處】git

經常使用方法等收集、添加擴展類、工具類方法、請求方法封裝(包括圖片上傳等)等等 擁有不少方便快捷功能 ^_^github

用法:

只須要導入BOBsKit.h 頭文件就行
 // #import "BOBsKit.h"

依賴三方庫:

pod 'SDWebImage', '~> 3.7.5'
  pod 'MBProgressHUD', '~> 0.9.2'
  pod 'AFNetworking', '~> 3.1.0'
  pod 'MJExtension'

簡單舉例一二說明:一、方便快捷設置屬性值

一、爲按鈕新增title屬性:

UIButton *testButton = [[UIButton alloc]init];
testButton.title = @"按鈕標題";

二、避免崩潰,極大的加強APP的兼容性:

//(運行時重寫title點語法:Unbutton(添加),UIlabel,UItextfield,UItextView)
 UILabel等 賦值類型不匹配不會崩潰:從後臺獲取數據類型不匹配時正常運行。

 //重寫text屬性
 - (NSString *)text {
 return objc_getAssociatedObject(self, @selector(text));
 }

 - (void)setText:(NSString *)text {
    NSString *tempText = (text==nil||[text isKindOfClass:[NSNull class]]?@"":text);
    if ([tempText isKindOfClass:[NSNumber class]]) {
    tempText = [NSString stringWithFormat:@"%@",tempText];
  } else if (![tempText isKindOfClass:[NSString class]]) {
    tempText = @"";
  }
    objc_setAssociatedObject(self, @selector(text), tempText, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  }

三、快速設置UiView 位置大小屬性(因此UI控件包含Frame屬性時):

//快速設置寬度爲50:
testButton.width = 50;

//系統方法:
CGRect frame = self.frame;
frame.width = 50;
testButton.frame = frame;
相關文章
相關標籤/搜索