我們發現,慢慢積累了很多自己寫的各種類別的。
。今天,無私。張貼
1.nsdatefomatter
@inte***ce nsdateformatter (mycategory)
+ (id)dateformatter;
+ (id)dateformatterwithformat:(nsstring *)dateformat;
+ (id)defaultdateformatter;
@end
@implementation nsdateformatter (mycategory)
+ (id)dateformatter
+ (id)dateformatterwithformat:(nsstring *)dateformat
+ (id)defaultdateformatter
@end
2.nsdate
@inte***ce nsdate (mycategory)
- (nsstring *)timeintervaldescription;//距離當前的時間間隔
- (nsstring *)minutedescription;//精確到分鐘的日期
- (nsstring *)formatteddatedescription;//格式化日期
@end
@implementation nsdate (mycategory)
- (nsstring *)timeintervaldescription
else if (timeinterval < 3600) else if (timeinterval < 86400) else if (timeinterval < 2592000) else if (timeinterval < 31536000) else
}- (nsstring *)minutedescription
else if ([[dateformatter datefromstring:currentday] timeintervalsincedate:[dateformatter datefromstring:theday]] == 86400) else if ([[dateformatter datefromstring:currentday] timeintervalsincedate:[dateformatter datefromstring:theday]] < 86400 * 7) else
}- (nsstring *)formatteddatedescription
else if (timeinterval < 3600) else if (timeinterval < 21600) else if ([theday isequaltostring:currentday]) else if ([[dateformatter datefromstring:currentday] timeintervalsincedate:[dateformatter datefromstring:theday]] == 86400) else
}@end
3.uicolor
@inte***ce uicolor (mycategory)
+ (uicolor *)colorwithhexrgb:(nsstring *)hexrgbstring;
@end
@implementation uicolor (mycategory)
/*由16進製制字串獲取顏色*/
+ (uicolor *)colorwithhexrgb:(nsstring *)hexrgbstring
unsigned int colorcode = 0;
unsigned char redbyte, greenbyte, bluebyte;
if (hexrgbstring)
redbyte = (unsigned char) (colorcode >> 16);
greenbyte = (unsigned char) (colorcode >> 8);
bluebyte = (unsigned char) (colorcode); // masks off high bits
return [uicolor colorwithred:(float)redbyte/0xff green:(float)greenbyte/0xff blue:(float)bluebyte/0xff alpha:1.0];
}@end
4.uiimage
@inte***ce uiimage (mycategory)
//拉伸、平鋪介面
- (uiimage *)resizableimagewithcompatiblecapinsets:(uiedgeinsets)capinsets resizingmode:(uiimageresizingmode)resizingmode;
//以scaletofit方式拉伸後的cgsize
- (cgsize)sizeofscaletofit:(cgsize)scaledsize;
//將轉向調整為向上
- (uiimage *)fixorientation;
//以scaletofit方式壓縮
- (uiimage *)compressedimagewithsize:(cgsize)compressedsize;
@end
@implementation uiimage (mycategory)
/*獲取當前主題包的指定*/
+ (uiimage *)themeimagenamed:(nsstring *)name
}/*拉伸、平鋪介面。相容ios5+*/
- (uiimage *)resizableimagewithcompatiblecapinsets:(uiedgeinsets)capinsets resizingmode:(uiimageresizingmode)resizingmode
else if (version >= 5.0) else
} else
}/*以scaletofit方式拉伸後的cgsize*/
- (cgsize)sizeofscaletofit:(cgsize)scaledsize
else
}/*將轉向調整為向上*/
- (uiimage *)fixorientation
uigraphicsbeginimagecontextwithoptions(self.size, no, self.scale);
[self drawinrect:cgrectmake(0.0, 0.0, self.size.width, self.size.height)];
uiimage *fixedimage = uigraphicsgetimagefromcurrentimagecontext();
uigraphicsendimagecontext();
return fixedimage;
}/*以scaletofit方式壓縮*/
- (uiimage *)compressedimagewithsize:(cgsize)compressedsize
cgsize scaledsize = [self sizeofscaletofit:compressedsize];
//壓縮大小。調整轉向
uigraphicsbeginimagecontext(scaledsize);
[self drawinrect:cgrectmake(0.0, 0.0, scaledsize.width, scaledsize.height)];
uiimage *compressedimage = uigraphicsgetimagefromcurrentimagecontext();
uigraphicsendimagecontext();
return compressedimage;
}@end
5.uiview
@inte***ce uiview (mycategory)
- (void)startshakeanimation;//搖動動畫
- (void)stopshakeanimation;
- (void)startrotateanimation;//360°旋轉動畫
- (void)stoprotateanimation;
///截圖
- (uiimage *)screenshot;
@property (nonatomic) float top;
@property (nonatomic) float bottom;
@property (nonatomic) float left;
@property (nonatomic) float right;
@end
@implementation uiview (mycategory)
/*截圖*/
- (uiimage *)screenshot
#pragma mark - animation
- (void)startshakeanimation
- (void)stopshakeanimation
- (void)startrotateanimation
- (void)stoprotateanimation
-(float)top
-(float)bottom
-(float)left
-(float)right
@end
iOS之類別 category 的使用
1 類別介面語法格式 inte ce 已有類 類別名 定義方法 end 2 類別實現部分語法格式 implementation 已有類 類別名 方法實現 end 3 例項 為nsnumber新增乙個類別 1 nsnumber fk.h import 定義乙個類別 inte ce nsnumber f...
IOS開發 經常使用站點集合
4.開原始碼庫和版本號管理系統 5.it技術論壇 國外技術分享 6.支付寶 支付託 商家服務 7.qq互聯 開放平台 8.微博 開放平台 9.人人網 開放平台 10.it 社群 11.社群站點 iphone 共享 論壇 觸控科技 cocos2d x 遊戲引擎 12.開源中國 多平台 13.mupdf...
iOS 靜態庫中使用類別 Category
如果我們生成乙個靜態庫,庫中包含類別的定義以及使用,在使用庫的專案中,當用到類別的方法時,程式就會crash,找不到對應的方法實現 環境 xcode6 遇到這種問題,解決辦法有兩個 1 一是把類別檔案新增進來 如果是第三方庫,就不太現實 2 目標工程中新增鏈結選項 all load。即在目標工程的t...