2015-02-17 1 views
1

У меня есть следующие 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.tintColorUIViewController.

self.navigationController.navigationBar.tintColor = [UIColor redColor];

Если удалить tintColor, то они всегда голубые.

+0

Привет @gotnull, у меня нет ответа, просто FYI, есть инструмент под названием [PaintCode] (http://www.paintcodeapp.com/), который выводит код для графики, который вы рисуете. Я часто использую это, чтобы увидеть, как CoreGraphics делает что-то. Существует пробная версия, которую вы можете использовать. –

ответ

0

Фиксированный с помощью следующих действий:

buttonController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[[self class] defaultImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(toggleLeftPanel:)]; 

То, что происходит в том, что изображение визуализируется как «шаблон», то есть, только альфа-канал втягивается с цветом приходит из navigationBar ' s tintColor.