0

I'm getting into IB_DESIGNABLE, and I've stumbled over an issue.

When I set the tintColor of my custom view with IB, it is rendered in the right way in the IB.

enter image description here

But when I run it on the device it is displayed with default tintColor.

enter image description here

#pragma mark - UIView

- (void)drawRect:(CGRect)rect {
    [self drawCircleRadius:MIN(rect.size.width / 2, rect.size.height / 2) - self.lineWidth / 2.f
                      rect:rect
                startAngle:self.startAngleRadians
                  endAngle:self.endAngleRadians
                 lineWidth:self.lineWidth];
}

#pragma mark - private methods

- (void)drawCircleRadius:(CGFloat)radius
                    rect:(CGRect)rect
              startAngle:(CGFloat)startAngle
                endAngle:(CGFloat)endAngel
               lineWidth:(CGFloat)lineWidth {
    UIBezierPath* bezierPath = [UIBezierPath bezierPath];
    [self.tintColor setStroke];
    [bezierPath addArcWithCenter:CGPointMake(rect.size.width / 2, rect.size.height / 2)
                          radius:radius
                      startAngle:startAngle
                        endAngle:endAngel
                       clockwise:YES];

    bezierPath.lineWidth = lineWidth;
    [bezierPath stroke];
}

What the difference? Why is it displayed with the default tint color in the device, and correctly displayed in IB?

UPDATE:

#import <UIKit/UIKit.h>

IB_DESIGNABLE
@interface PKCircleView : UIView

@property (nonatomic, assign) IBInspectable CGFloat startAngleRadians;
@property (nonatomic, assign) IBInspectable CGFloat endAngleRadians;
@property (nonatomic, assign) IBInspectable CGFloat lineWidth;

@end
BergP
  • 3,453
  • 4
  • 33
  • 58
  • I ran your code and it worked fine in IB, simulator and on device. Problem must be somewhere else. Maybe show your header file for the custom view? Here is what I used: `#import IB_DESIGNABLE @interface Circle : UIView @property (nonatomic) IBInspectable double lineWidth; @property (nonatomic) IBInspectable double startAngleRadians; @property (nonatomic) IBInspectable double endAngleRadians; @end` – picciano May 31 '15 at 13:15
  • @picciano yes, looks like the same. – BergP May 31 '15 at 13:22

1 Answers1

0

The issue was on that line

 self.tintColor = [UIColor defaultDwonloadButtonBlueColor];

:

static PKCircleView *CommonInit(PKCircleView *self) {
    if (self != nil) {
        self.backgroundColor = [UIColor clearColor];
        self.startAngleRadians = M_PI * 1.5;
        self.endAngleRadians = self.startAngleRadians + (M_PI * 2);
        self.lineWidth = 1.f;
        self.tintColor = [UIColor defaultDwonloadButtonBlueColor];
    }
    return self;
}

@implementation PKCircleView

#pragma mark - initialization

- (id)initWithCoder:(NSCoder *)decoder {
    return CommonInit([super initWithCoder:decoder]);
}

- (instancetype)initWithFrame:(CGRect)frame {
    return CommonInit([super initWithFrame:frame]);
}

it seems like setTintColor from IB is called before init... methods.

BergP
  • 3,453
  • 4
  • 33
  • 58