【发布时间】:2013-09-27 11:13:24
【问题描述】:
如何在ios中使用beizer路径之类的绘制字母E?
我尝试使用 E 的普通图像,但它会根据屏幕分辨率而变化,但它应该不会变化,所以我将通过编码进行绘制。
【问题讨论】:
标签: ios calayer bezier quartz-core
如何在ios中使用beizer路径之类的绘制字母E?
我尝试使用 E 的普通图像,但它会根据屏幕分辨率而变化,但它应该不会变化,所以我将通过编码进行绘制。
【问题讨论】:
标签: ios calayer bezier quartz-core
您可以创建自定义视图。 (UIView)的子类。并像这样改变它的draw rect方法。
- (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);
}
您可以根据需要更改线条颜色、宽度或任何其他属性。
编辑: 对于中心,
先定义E字符的宽度,比方说;
#define VERTICAL_LINE 40
#define TOP_HORIZONTAL_LINE 40
#define CENTER_HORIZONTAL_LINE 40
#define BOTTOM_HORIZONTAL_LINE 40
#define LINE_PIECE 20
还有drawRect方法;
- (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);
}
【讨论】: