【问题标题】:How to change the text of color in drawRect Method如何在 drawRect 方法中更改颜色文本
【发布时间】:2013-01-28 08:01:13
【问题描述】:

我想在我的switchColor 方法中单击颜色按钮时更改drawRect: 方法中文本的​​颜色。

这是我的代码:

- (void)drawRect:(CGRect)rect withColor:(UIColor*) color

{ CGContextRef 上下文 = UIGraphicsGetCurrentContext();

CGColorRef red = color.CGColor;
NSLog (@"color is %@",red);
//CGColorRef color = (__bridge CGColorRef)([UIColor colorWithRed:0.0 green:3.0 blue:2.0 alpha:1.0]);

CGContextFillRect(context, CGRectMake(130,200,120,120));
CGContextSetFillColorWithColor(context,red);
CGContextFillEllipseInRect(context, CGRectMake(130, 200, 120, 120));

}

错误 CGContextFillRects: 无效的上下文 0x0...请帮助我

【问题讨论】:

  • 向我们展示一些您迄今为止尝试过的代码
  • 我正在尝试使用 switchColor: 方法将按钮添加到视图中......请帮助我

标签: ios drawrect


【解决方案1】:

使用

CGContextSetFillColorWithColor(context, textColor);

【讨论】:

  • 而不是直接给 textcolor 我想用不同的按钮颜色调用方法
  • 不用CG的方法是[[UIColor redColor] set];或任何你想要的颜色。
  • CGColorRef red = [[UIColor redColor] CGColor]; CGContextFillRect(context, CGRectMake(130,200,120,120)); CGContextSetFillColorWithColor(context,red);这是获取颜色的方法吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-03
  • 1970-01-01
相关资源
最近更新 更多