UIImage
UIImage是用來(lái)顯示圖像的對(duì)象徐紧。我們可以通過(guò)文件、接收到原始的數(shù)據(jù)或者Quartz圖像對(duì)象來(lái)創(chuàng)建UIImage對(duì)象意乓。
- imageNamed:類方法拆檬,根據(jù)指定的文件名返回UIImage對(duì)象
- imageWithData:類方法,根據(jù)指定的NSData對(duì)象創(chuàng)建UIImage對(duì)象
- imageWithContentOfFile:通過(guò)文件加載指定路徑下的內(nèi)容獲得UIImage對(duì)象
- imageWithCGImage:通過(guò)Quartz 2D對(duì)象創(chuàng)建UIImage對(duì)象
- imageWithCIImage:通過(guò)Core Image對(duì)象創(chuàng)建UIImage對(duì)象
- size屬性:圖像的大小屡贺,得到一個(gè)CGSize結(jié)構(gòu)體蠢棱,其中包括了寬度(width)和高度(height)
// 此種方式只能小的圖片
UIImage *image1 = [UIImage imageNamed:@"abc"];
NSString * strPath = [[NSBundle mainBundle]
pathForResource:@"one" ofType:@"png"];
// 該方式即使加載很大的圖片也不會(huì)使程序崩潰
UIImage *image2 = [UIImage imageWithContentsOfFile:strPath];
// 通過(guò)制定URL得到的數(shù)據(jù)創(chuàng)建圖片對(duì)象
UIImage *image3 =[UIImage imageWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString:
@"https://www.baidu.com/img/bg.png"]]];
NSTimer
//下面五個(gè)參數(shù)依次為:
1.間隔時(shí)間;
2.事件源甩栈;
3.SEL回調(diào)方法泻仙;
(selector指定的方法必須是帶一個(gè)參數(shù)的方法,并且那個(gè)參數(shù)的類型是NSTimer *)量没;
4.此參數(shù)可以為nil什么也不干玉转,也可以;
5.當(dāng)YES時(shí)殴蹄,定時(shí)器會(huì)不斷循環(huán)直至失效或被釋放究抓,當(dāng)NO時(shí),定時(shí)器會(huì)循環(huán)發(fā)送一次就失效袭灯。
NSTimer *timer = [NSTimer
scheduledTimerWithTimeInterval:0.05
target:self
selector:@selector(buttonClicked:)
userInfo:nil
repeats:YES];
- (void)buttonClicked:(NSTimer *)sender {
NSString *string = (NSString *)[timer userInfo];
}
//用了時(shí)鐘一定要記得銷毀刺下,通知也是一樣
- (void) dealloc {
if (timer) {
[timer invalidate];
//這里指針設(shè)置為nil就不會(huì)出現(xiàn)野指針了
timer = nil;
}
}