展示效果:
請問:實現的步驟是什么?
第一步,繪制文字,需要實現如下步驟:1>初始化文字內容.2>設置文字的富文本屬性3>調用字符串的drawAtPoint方法進行文字的繪制.
第二步,使用UIKit來繪制圖片, UIImage一共有三種繪圖的方法. 1>平鋪2>以給入的點來繪制3>根據給入的矩形框來進行圖片的繪制.
//第一步代碼實現
------------------------------ HMDrawingView.m------------------------------
//繪制文字
- (void)drawRect:(CGRect)rect
{
// 1.初始化文字內容
NSString*text =@"Hello
World!";
// 2.設置文字的富文本屬性
NSMutableDictionary*attributesDict = [NSMutableDictionarydictionary];
attributesDict[NSFontAttributeName] = [UIFontsystemFontOfSize:20];
attributesDict[NSForegroundColorAttributeName] = [UIColorredColor];
attributesDict[NSStrokeWidthAttributeName] =@"5";
// 3.渲染文字內容
[textdrawAtPoint:CGPointMake(100,100)withAttributes:attributesDict];
}
//第二步代碼實現
------------------------------ HMDrawingView.m------------------------------
// UIKit繪制圖片
- (void)drawRect:(CGRect)rect
{
// 1.平鋪圖片
UIImage*image = [UIImageimageNamed:@"me"];
[imagedrawAsPatternInRect:rect];
// 2.使用起始點來繪制圖片->默認的尺寸就是圖片的尺寸
UIImage*image = [UIImageimageNamed:@"me"];
[imagedrawAtPoint:CGPointMake(100,100)];
// 3.使用矩形框來繪制圖片->默認的尺寸就是矩形框的尺寸,如果圖片非常小,就會被拉伸
UIImage*image = [UIImageimageNamed:@"me"];
[imagedrawInRect:CGRectMake(50,50,300,300)];
}