Seb*_*Seb 2 nsstring uiview drawrect ios
我有代码在UIView子类中的drawRect方法内进行自定义渲染.我试图渲染文本使用[NSString drawInRect]哪个很好,但它总是以白色显示.经过大量的谷歌搜索和浏览后,我无法找到如何更改文本的颜色.任何建议都会很棒.
编辑 下面是我的drawRect实现中的代码片段
if(self.state != UIControlStateHighlighted)
{
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, color);
CGContextSetShadowWithColor(context, CGSizeMake(0, 2), 3.0, shadowColor);
CGContextAddPath(context, path);
CGContextFillPath(context);
[title drawInRect:rect withFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];
CGContextRestoreGState(context);
}
Run Code Online (Sandbox Code Playgroud)
小智 7
在绘制文本之前,您必须设置颜色.试试这个,
[[UIColor blackColor] set]; [title drawInRect:rect withFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];
| 归档时间: |
|
| 查看次数: |
6641 次 |
| 最近记录: |