Tag: drawable

在UIView的-drawRect:方法中绘制彩色文本

我想在我的UIView子类中绘制彩色的文字。 现在我正在使用Single View应用程序模板(用于testing)。 除了drawRect:方法之外,没有任何修改。 文本被绘制出来,但是无论我设置什么颜色,它总是黑色的。 – (void)drawRect:(CGRect)rect { UIFont* font = [UIFont fontWithName:@"Arial" size:72]; UIColor* textColor = [UIColor redColor]; NSDictionary* stringAttrs = @{ UITextAttributeFont : font, UITextAttributeTextColor : textColor }; NSAttributedString* attrStr = [[NSAttributedString alloc] initWithString:@"Hello" attributes:stringAttrs]; [attrStr drawAtPoint:CGPointMake(10.f, 10.f)]; } 我也试过[[UIColor redColor] set]无济于事。 回答: NSDictionary * stringAttrs = @ {NSFontAttributeName:font,NSForegroundColorAttributeName:textColor};

CG中的纹理线

我正在为iOS的绘图应用程序工作。 在这个应用程序中,我需要绘制质感的线条。 对于这个我正在使用这种方法 。但是质地太小而不是形状。 我想知道我做错了什么,我该如何解决它。 这是我更新的代码 – CGPoint mid1 = midPoint(previousPoint1, previousPoint2); CGPoint mid2 = midPoint(currentPoint, previousPoint1); [curImage drawAtPoint:CGPointMake(0, 0)]; CGContextRef context = UIGraphicsGetCurrentContext(); [self.layer renderInContext:context]; CGContextMoveToPoint(context, mid1.x, mid1.y); CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y); CGContextSetLineCap(context, kCGLineCapRound); CGContextSetLineJoin(context, kCGLineJoinRound); CGContextSetLineWidth(context, self.lineWidth); //trans layer CGContextBeginTransparencyLayer(context, nil);// CGRect rect=CGContextGetPathBoundingBox (context);// CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);// //trans layer end CGContextSetShouldAntialias(context, YES); […]