1巧涧、設(shè)置UILabel行間距
NSMutableAttributedString*?attrString?=?[[NSMutableAttributedString??alloc]?initWithString:label.text];
NSMutableParagraphStyle?*style?=?[[NSMutableParagraphStyle?alloc]?init];
[style?setLineSpacing:20];
[attrString?addAttribute:NSParagraphStyleAttributeName?value:style?range:NSMakeRange(0,?label.text.length)];
label.attributedText?=?attrString;
2、UILabel顯示不同顏色字體
NSMutableAttributedString?*?string?=?[[NSMutableAttributedString?alloc]?initWithString:label.text];
[string?addAttribute:NSForegroundColorAttributeName?value:[UIColor?redColor]?range:NSMakeRange(0,5)];
[string?addAttribute:NSForegroundColorAttributeName?value:[UIColor?greenColor]?range:NSMakeRange(5,6)];
[string?addAttribute:NSForegroundColorAttributeName?value:[UIColor?blueColor]?range:NSMakeRange(11,5)];
label.attributedText?=?string;
,247);mj?8dx?
3导而、計(jì)算UILabel上某段文字的frame
@implementation?UILabel?(TextRect)
-?(CGRect)boundingRectForCharacterRange:(NSRange)range
{
NSTextStorage?*textStorage?=?[[NSTextStorage?alloc]?initWithAttributedString:[self?attributedText]];
NSLayoutManager?*layoutManager?=?[[NSLayoutManager?alloc]?init];
[textStorage?addLayoutManager:layoutManager];
NSTextContainer?*textContainer?=?[[NSTextContainer?alloc]?initWithSize:[self?bounds].size];
textContainer.lineFragmentPadding?=?0;
[layoutManager?addTextContainer:textContainer];
NSRange?glyphRange;
[layoutManager?characterRangeForGlyphRange:range?actualGlyphRange:&glyphRange];
return?[layoutManager?boundingRectForGlyphRange:glyphRange?inTextContainer:textContainer];
}
4、比較兩個(gè)NSDate相差多少小時(shí)
NSDate*?date1?=?someDate;
NSDate*?date2?=?someOtherDate;
NSTimeInterval?distanceBetweenDates?=?[date1?timeIntervalSinceDate:date2];
double?secondsInAnHour?=?3600;
//?除以3600是把秒化成小時(shí)隔崎,除以60得到結(jié)果為相差的分鐘數(shù)
NSInteger?hoursBetweenDates?=?distanceBetweenDates?/?secondsInAnHour;
5今艺、播放一張張連續(xù)的圖片
//?加入現(xiàn)在有三張圖片分別為tu1、tu2爵卒、tu3
//?方法一
imageView.animationImages?=?@[[UIImage?imageNamed:@"tu1"],?[UIImage?imageNamed:@"tu2"],?[UIImage?imageNamed:@"tu3"]];
imageView.animationDuration?=?1.0;
//?方法二
imageView.image?=?[UIImage?animatedImageNamed:@"tu"?duration:1.0];
//?方法二解釋下虚缎,這個(gè)方法會(huì)加載tu為前綴的,后邊0-1024钓株,也就是tu0实牡、tu1一直到tu1024
6、防止離屏渲染為image添加圓角
//?image分類
-?(UIImage?*)circleImage
{
//?NO代表透明
UIGraphicsBeginImageContextWithOptions(self.size,?NO,?1);
//?獲得上下文
CGContextRef?ctx?=?UIGraphicsGetCurrentContext();
//?添加一個(gè)圓
CGRect?rect?=?CGRectMake(0,?0,?self.size.width,?self.size.height);
//?方形變圓形
CGContextAddEllipseInRect(ctx,?rect);
//?裁剪
CGContextClip(ctx);
//?將圖片畫上去
[self?drawInRect:rect];
UIImage?*image?=?UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return?image;
}
7轴合、查看系統(tǒng)所有字體
//?打印字體
for?(id?familyName?in?[UIFont?familyNames])?{
NSLog(@"%@",?familyName);
for?(id?fontName?in?[UIFont?fontNamesForFamilyName:familyName])?NSLog(@"??%@",?fontName);
}
NSInteger?i?=?arc4random();
8创坞、獲取隨機(jī)數(shù)
NSInteger?i?=?arc4random();
9、AVPlayer視頻播放完成的通知監(jiān)聽
[[NSNotificationCenter?defaultCenter]
addObserver:self
selector:@selector(videoPlayEnd)
name:AVPlayerItemDidPlayToEndTimeNotification
object:nil];
15受葛、判斷一個(gè)字符串是否為數(shù)字
NSCharacterSet?*notDigits?=?[[NSCharacterSet?decimalDigitCharacterSet]?invertedSet];
if?([str?rangeOfCharacterFromSet:notDigits].location?==?NSNotFound)
{
//?是數(shù)字
}?else
{
//?不是數(shù)字
}
以上內(nèi)容并非原創(chuàng)题涨,在各個(gè)平臺(tái)搜集整理的偎谁,初來(lái)乍到,多多關(guān)照