代碼創建
/**
創建UIImageView
*/
UIImageView * imageView=[[UIImageView alloc]init];
/**
設置尺寸位置
*/
imageView.frame=(CGRect){{50,50},{230,230}};
/**
創建圖片
*/
UIImage * image=[[UIImage alloc]init];
/**
獲取圖片
*/
image=[UIImage imageNamed:@"圖片名稱"];
/**
把圖片給容器
*/
imageView.image=image;
/**
->帶有scale單詞的 <圖片有可能被拉伸>
UIViewContentModeScaleToFill
//將圖片拉伸填充整個imageView
//圖片顯示的尺寸跟imageView的尺寸是一樣的
->帶有scale單詞的,並且帶有aspect單詞的:可能會被拉伸,但是會保持圖片原來的寬高比
UIViewContentModeScaleAspectFit
//保證剛好能看到圖片的全部
UIViewContentModeScaleAspectFill
//拉伸至圖片的寬度或者高度跟imageView一樣
->不帶有scale的單詞<圖片絕對不會被拉伸>,保持圖片原來的寬度和高度
*/
imageView.contentMode=UIViewContentModeScaleAspectFit;
/**
超出部分被剪裁
*/
imageView.clipsToBounds=YES;
[self.view addSubview:imageView];
圖片加載
- 沒有緩存
NSString *file = [[NSBundle mainBundle] pathForResource:@"圖片名" ofType:@"圖片擴展名"];
UIImage *image = [UIImage imageWithContentOfFile:file];
*只要方法名帶有file的,都是傳全路徑
使用場合:圖片比較大,使用頻率比較低
建議:不需要緩存的圖片不能放在Images.xcassets中
- 有緩存
UIImage *image =[UIImage imageNamed:@"圖片名"];
使用場合:圖片比較小、使用頻率比較高
建議:把需要緩存的圖片放到Images.xcassets
音頻文件播放
// 創建一個音頻文件的URL(URL就是文件的路徑對象)
NSURL *url = [[NSBundle mainBundle] URLForResource:@"音頻文件名" withExtention:@“音頻文件擴展名”];
-- 另一寫法
NSURL *url = [[NSBundle mainBundle] URLForResource:@"音頻文件名.音頻文件擴展名" withExtention:nil];
// 創建播放器
self.palyer = [AVPlayer playerWithURL:url];
[self.player play];
延遲調用方法
[objc performSelector:@selector(stand:) withObject:@"123" afterDelay:10];
// 10秒后調用objc的stand:方法,並且傳遞@“123”參數
// withObject可以是任意對象
