通常使用UIKit給咱們提供的繪圖來繪製一些文字,圖片這些東西.字體
UIKit給咱們提供畫圖的方法底層也是分爲四步.因此也必須在drawRect方法當中去寫.spa
1.如何畫文字?圖片
先建立好要畫的文字ip
使用UIKit提供的方法進行繪製.it
方法說明:io
drawAtPoint:要畫到哪一個位置table
withAttributes:文本的樣式.class
[str drawAtPoint:CGPointZero withAttributes:nil];方法
2.如何添加繪製文字屬性?im
經過繪製方法的最後一個屬性withAttributes來設置文字屬性.
它要求傳入的是一個字典.它是經過字典的key和Value的形式來設置文字樣式.
那傳什麼key,什麼值咱們能夠在UIKit頭文件當中的NSAttributedString類當中去找.
使用形式以下:
建立一個可變的字典,設置key,value
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
字體
dict[NSFontAttributeName] = [UIFont systemFontOfSize:50];
顏色
dict[NSForegroundColorAttributeName] = [UIColor redColor];
設置邊框顏色
dict[NSStrokeColorAttributeName] = [UIColor redColor];
dict[NSStrokeWidthAttributeName] = @1;
陰影
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowOffset = CGSizeMake(10, 10);
shadow.shadowColor = [UIColor greenColor];
shadow.shadowBlurRadius = 3;
dict[NSShadowAttributeName] = shadow;
3.drawAtPoint:和drawInRect:的區別?
drawAtPoint:不可以自動換行
drawInRect:可以自動換行
4.若是繪製圖片?
繪製圖片一樣開始要先把圖片素材導入.
AtPoint:參數說明圖片要繪製到哪一個位置.
經過調用UIKit的方法drawAtPoint:CGPointZero方法進行繪製;
5.在繪製圖片過程中.drawAtPoint:和drawInRect:兩個方法的區別?
drawAtPoint:繪製出來的圖圖片跟圖片的實際尺寸同樣大
drawInRect:使用這個方法繪製出來的圖片尺寸會和傳入的rect區域同樣大.
6.若是進行平鋪圖片?
[image drawAsPatternInRect:rect];
7.如何選用UIKit提供的方法快速畫一個矩形?
快速的用矩形去填充一個區域
UIRectFill(rect);
8.如何利用UIKit裁剪一個區域?
UIRectClip(CGRectMake(0, 0, 50, 50));
這個方法必需要設置好裁剪區域,纔能有裁剪