iOS設備的多樣性
曾經很簡單,現在越來越復雜
iOS設備的多樣性
以上還不包含iPad、?Watch、Apple TV等等
更詳細的清單可見:https://en.wikipedia.org/wiki/List_of_iOS_devices
界面適配會在后面講
Assert Catalog
管理項目里的圖片
Assert Catalog
可以可視化的管理各尺寸的圖片
1pt,1x圖片尺寸為1px,2x圖片尺寸為2px,3x圖片尺寸為3px
圖片切片
切片多用于方框,可以使圖片在拉伸時四角保持一定的比例
在Attribute Inspector -> slicing
或點擊Show Slicing
圖片切片
矢量圖
- PDF格式的矢量圖創建
- Illustrator 或 Inkscape 到處 PDF
- Keynote 也可以
- @1x尺寸
- 在Assert Catalog里設置
- Scale Factors: Single Vector
- 然后將矢量圖拖進Universal -> All
Vector With Override : 優先使用1x、2x、3x版本,若未提供,則使用矢量圖
UIImageView
Mode:圖片拉伸方式
Alpha:半透明度,比較影響性能
- 用UIImageView 顯示圖片
- .image屬性
- 圖片從哪里來的?
- 在IB里選圖片意味著
- 圖片打包在mainBundle里
- 系統自動緩存,且不會釋放
- 在IB里選圖片意味著
UIImage 對象
加載App bundle里的圖片
//會自動緩存到內存中,且不會釋放
image = [UIImage imageNamed:@"mypic"];
//會自動緩存到內存中,且不會釋放,bundle及其他參數可以自己指定
image = [UIImage imageNamed:@"mypic" inBundle:nil conpatibleWithTraitCollection:nil];
//不會自動緩存到內存中
NSURL* url = [[NSBundle mainBundle] URLForResource:@"mypic" withExtension:@"png"];
UIImage* image = [UIImage imageWithContentsOfFile:url.path];
加載文件里的圖片
//不會自動緩存到內存中
UIImage* image = [UIImage imageWithContentsOfFile:path];
//不會自動緩存到內存中
UIImage* image = [UIImage imageWithData:data];
使用animatedImageNamed:
方法,系統會自動識別類似image01.xx、image02.xx。。。這樣的命名,然后將他們顯示為動圖:
UIImage *image = [UIImage animatedImageNamed:@"image" duration: 1.0];
但是要注意內存的占用