ios繪製基本圖形之浮水印背景

來源:互聯網
上載者:User

標籤:

 1 @interface NJTextImage : UIView 2 @end 3  4  5 @implementation NJTextImage 6  7 - (void)drawRect:(CGRect)rect 8 {     9 //    [self test];10 //    1.載入圖片到記憶體中11     UIImage *image = [UIImage imageNamed:@"bg"];12     13     // 利用OC方法將圖片繪製到layer上14     // 將圖片繪製到指定的位置15     [image drawAtPoint:CGPointMake(0, 0)];16     17     // 利用drawInRect方法繪製圖片到layer, 是通過展開原有圖片18 //    [image drawInRect:CGRectMake(0, 0, 40, 40)];19     20     // 利用drawAsPatternInRec方法繪製圖片到layer, 是通過平鋪原有圖片21 //    [image drawAsPatternInRect:CGRectMake(0, 0, 320, 480)];22     23 }24 25 - (void)test26 {27     // 畫文字28     NSString *str = @"天氣好熱地方和電腦的開了房間了開始的解放路口時間瘋狂的老師;快瘋了;SD卡;焚枯食淡;李開複;順豐快遞說了;開發;展開放假快樂的設計風格看了就打算離開房間的數量會計分錄開始覺得";29     30     // 1.擷取上下文31     //    CGContextRef ctx = UIGraphicsGetCurrentContext();32     // 2.繪圖33     // 不推薦使用C語言的方法繪製文字, 因為quraz2d中的座標系和UIkit中的座標系不一致, 繪製出來的文字是顛倒的, 而且通過C語言的方法繪製文字相當麻煩34     //    CGContextSelectFont(<#CGContextRef c#>, <#const char *name#>, <#CGFloat size#>, <#CGTextEncoding textEncoding#>)35     //    CGContextShowText(ctx, <#const char *string#>, <#size_t length#>)36     37     // 繪製矩形38     // 1.擷取上下文39     CGContextRef ctx = UIGraphicsGetCurrentContext();40     // 2.繪圖41     CGContextAddRect(ctx, CGRectMake(50, 50, 100, 100));42     // 3.渲染43     CGContextStrokePath(ctx);44     45     NSMutableDictionary *md = [NSMutableDictionary dictionary];46     // 設定文字顏色47     md[NSForegroundColorAttributeName] =[UIColor redColor];48     // 設定文字背景顏色49     md[NSBackgroundColorAttributeName] = [UIColor greenColor];50     // 設定文字大小51     md[NSFontAttributeName] = [UIFont systemFontOfSize:20];52     53 //    將文字繪製到指點的位置54 //    [str drawAtPoint:CGPointMake(10, 10) withAttributes:md];55     56 //    將文字繪製到指定的範圍內, 如果一行裝不下會自動換行, 當文字超出範圍後就不顯示57     [str drawInRect:CGRectMake(50, 50, 100, 100) withAttributes:nil];58     59     60 }61 62 @end

 

ios繪製基本圖形之浮水印背景

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.