繪制文字和圖片
繪制文字
NSString *str = @"asfdsfsdf";
// Attributes:文本屬性
NSMutableDictionary *textDict = [NSMutableDictionary dictionary];
// 設(shè)置文字顏色
textDict[NSForegroundColorAttributeName] = [UIColor redColor];
// 設(shè)置文字字體
textDict[NSFontAttributeName] = [UIFont systemFontOfSize:30];
// 設(shè)置文字的空心顏色和寬度
textDict[NSStrokeWidthAttributeName] = @3;
textDict[NSStrokeColorAttributeName] = [UIColor yellowColor];
// 創(chuàng)建陰影對(duì)象
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor greenColor];
shadow.shadowOffset = CGSizeMake(4, 4);
shadow.shadowBlurRadius = 3;
textDict[NSShadowAttributeName] = shadow;
// 繪制,不會(huì)換行
[str drawAtPoint:CGPointZero withAttributes:textDict];
// 會(huì)換行
[str drawInRect:rect withAttributes:textDict];
繪制圖片
//設(shè)置裁剪區(qū)域冒窍,一旦設(shè)置了裁剪區(qū)域,“再”繪制的圖像综液,就僅能顯示裁剪區(qū)域范圍內(nèi)的內(nèi)容
//需要注意的是谬莹,設(shè)置了裁剪區(qū)域之后,在繪圖届良,否則裁剪區(qū)域無效
UIRectClip(CGRectMake(0, 0, 50, 50));
UIImage *image = [UIImage imageNamed:@"阿貍頭像"];
// 默認(rèn)繪制的內(nèi)容尺寸跟圖片尺寸一樣大
[image drawAtPoint:CGPointZero];
// 繪制圖像在對(duì)應(yīng)的尺寸內(nèi),會(huì)拉伸或壓縮圖片大小
[image drawInRect:rect];
// 繪圖圖像乞而,平鋪慢显,按照?qǐng)D片原尺寸繪制
[image drawAsPatternInRect:rect];
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者