zoukankan      html  css  js  c++  java
  • iPhone中自绘实现步骤

    1. 继承@interface MyView : UIView {

    2. 实现- (void)drawRect:(CGRect)rect

    3. 调用addSubView把新生成的view加入进来显示:addSubView[window addSubview:viewController.view];

    4.示例代码

     1 - (void)drawRect:(CGRect)rect {
     2     // create the bitmap context
     3     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
     4     CGContextRef context = CGBitmapContextCreate(nil,100,100,8,400, colorSpace,kCGImageAlphaPremultipliedLast);
     5     CFRelease(colorSpace);
     6     
     7     //    create an arrow image
     8     // set the fill color
     9     CGColorRef fillColor = [[UIColor blackColor] CGColor];
    10     CGContextSetFillColor(context, CGColorGetComponents(fillColor));
    11     
    12     CGContextBeginPath(context);
    13     CGContextMoveToPoint(context, 8.0f, 13.0f);
    14     CGContextAddLineToPoint(context, 24.0f, 4.0f);
    15     CGContextAddLineToPoint(context, 24.0f, 22.0f);
    16     CGContextClosePath(context);
    17     CGContextFillPath(context);
    18     CGContextSelectFont ( context, "Arial", 10.f, kCGEncodingMacRoman );
    19     CGContextSetRGBFillColor ( context, 0.0f, 0.0f, 0.f, 1.f );
    20     CGContextSetShouldAntialias ( context, 0 );    
    21     CGContextShowText(context, "hh", 2);
    22     
    23     // convert the context into a CGImageRef
    24     CGImageRef image = CGBitmapContextCreateImage(context);
    25     CGContextRelease(context);
    26     
    27     UIImage* image2 = [UIImage imageWithCGImage:image];
    28     [image2 drawInRect:CGRectMake(0, 0, 120, 160)];
    29     
    30     NSString* myStr = @"中文";
    31     UIFont* font = [UIFont systemFontOfSize:12.0];
    32     [myStr drawInRect: CGRectMake(160, 240, 100, 130) withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
    33     
    34 }
  • 相关阅读:
    计算机漏洞安全相关的概念POC 、EXP 、VUL 、CVE 、0DAY
    开始使用kali的一些小问题:菜鸟瞎折腾
    nmap参数详解(罗列一下)
    安装kali之后必做的几件小事
    Debian下virtualBox增强功能出错
    ArcGIS Engine 基础功能(一)
    sublime 配置简单的python环境
    解决 ‘Could not fetch URL https://pypi.python.org’的问题
    golang基础语法学习
    大象盒子技术栈
  • 原文地址:https://www.cnblogs.com/dinghing154/p/2613847.html
Copyright © 2011-2022 走看看