uibezierpath绘图颜色配置方式

一开始我竟然使用CGContextSetStrokeColor(<#CGContextRef _Nullable c#>, <#const CGFloat * _Nullable components#>)这种方式来设置颜色。感觉也是可以的。但是当又绘制了带颜色的字符串后,就出问题了。线条,填充的颜色通通不对。

绘制字符串这样的:

NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.alignment = NSTextAlignmentCenter;
NSDictionary *[email protected]{NSParagraphStyleAttributeName:paragraph,
                         NSFontAttributeName:[UIFont systemFontOfSize:11.0f],
                         NSForegroundColorAttributeName:[UIColor colorWithWhite:1 alpha:0.6]};

NSString *tempstr=[NSString stringWithFormat:@"%d℃",max];
[tempstr drawInRect:CGRectMake(i*cwidth, tempHeight*step+tempHeight/2+4+4, cwidth, 14) withAttributes:dateAttr];

正解

UIBeZierPath设置颜色的方式,其实更简单了。直接用UIColor set就行了。唉。

setStroke
setFill