【发布时间】:2015-02-17 01:04:52
【问题描述】:
我有以下UIImage()
+ (UIImage *)defaultImage {
static UIImage *defaultImage = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(20.f, 13.f), NO, 0.0f);
[[UIColor yellowColor] setFill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 20, 1)] fill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 5, 20, 1)] fill];
[[UIColor blueColor] setFill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 10, 20, 1)] fill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 1, 20, 2)] fill];
[[UIColor greenColor] setFill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 6, 20, 2)] fill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 11, 20, 2)] fill];
defaultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
});
return defaultImage;
}
我在这里使用它:
buttonController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[self class] defaultImage] style:UIBarButtonItemStylePlain target:self action:@selector(toggleLeftPanel:)];
问题是setFill 颜色不起作用。矩形总是红色的。
它们实际上采用了 navigationBar.tintColor 和 UIViewController 的颜色。
self.navigationController.navigationBar.tintColor = [UIColor redColor];
如果我删除 tintColor,那么它们总是蓝色的。
【问题讨论】:
-
嗨@gotnull,我没有答案,仅供参考,有一个名为PaintCode 的工具可以为您绘制的图形输出代码。我经常用它来看看 CoreGraphics 是如何做事的。您可以使用一个试用版。
标签: objective-c uiimage uibezierpath