У меня есть следующие UIImage()
Настройка цвета заливки для UIBezierPath bezierPathWithRect
+ (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, у меня нет ответа, просто FYI, есть инструмент под названием [PaintCode] (http://www.paintcodeapp.com/), который выводит код для графики, который вы рисуете. Я часто использую это, чтобы увидеть, как CoreGraphics делает что-то. Существует пробная версия, которую вы можете использовать. –