2013-09-27 30 views
0

如何在ios上绘制字母E使用beizer路径或什么?在ios中绘制字母E

我尝试了E的正常图像,但它根据屏幕分辨率而变化,但它不应该变化,所以我要通过编码绘制。

回答

0

您可以创建自定义视图。 (子类的UIView)并改变其绘制矩形方法这样

- (void)drawRect:(CGRect)rect { 
    [super drawRect:rect]; 

    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor); 

    CGContextSetLineWidth(context, 3.0); 

    CGContextMoveToPoint(context, 0,0); 

    CGContextAddLineToPoint(context, 0, 60); 

    CGContextMoveToPoint(context, 0,0); 

    CGContextAddLineToPoint(context, 30, 0); 

    CGContextMoveToPoint(context, 0, 30); 

    CGContextAddLineToPoint(context, 20, 30); 

    CGContextMoveToPoint(context, 0, 60); 

    CGContextAddLineToPoint(context, 30, 60); 

    CGContextStrokePath(context); 
} 

你可以改变线条的颜色,宽度或任何其他属性,只要你想

编辑:。 为中心,

首先定义é字符的宽度,让说,

#define VERTICAL_LINE 40 
#define TOP_HORIZONTAL_LINE 40 
#define CENTER_HORIZONTAL_LINE 40 
#define BOTTOM_HORIZONTAL_LINE 40 
#define LINE_PIECE 20 

而且drawRe ct方法;

- (void)drawRect:(CGRect)rect { 
    [super drawRect:rect]; 

    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor); 

    CGContextSetLineWidth(context, 3.0); 


    // assumed top and bottom lines are equal width 

    CGFloat x, y; 
    x = (self.frame.size.width - MAX(TOP_HORIZONTAL_LINE,CENTER_HORIZONTAL_LINE))/2; 
    y = (self.frame.size.height - VERTICAL_LINE)/2; 

    CGContextMoveToPoint(context, x, y); 

    CGContextAddLineToPoint(context, x, y + VERTICAL_LINE); 

    CGContextMoveToPoint(context, x,y); 

    CGContextAddLineToPoint(context, x+TOP_HORIZONTAL_LINE, y); 

    CGContextMoveToPoint(context, x, y+LINE_PIECE); 

    CGContextAddLineToPoint(context, x+CENTER_HORIZONTAL_LINE, y+LINE_PIECE); 

    CGContextMoveToPoint(context, x, y+VERTICAL_LINE); 

    CGContextAddLineToPoint(context, x + BOTTOM_HORIZONTAL_LINE, y + VERTICAL_LINE); 

    // and now draw the Path! 
    CGContextStrokePath(context); 
} 
+0

:Thanks.It的工作:) fine.But如何使它的视图的中心? – user2791408

+0

我编辑了答案,希望有帮助。 – caglar

+0

工作就像一个魅力! – user2791408