IB_DESIGNABLE tintColor问题

时间:2015-05-31 12:47:19

标签: ios interface-builder uicolor tintcolor ibdesignable

我正在进入IB_DESIGNABLE,我偶然发现了一个问题。

当我使用IB设置自定义视图的tintColor时,它会以正确的方式呈现在IB中。

enter image description here

但是当我在设备上运行时,会显示默认的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];
}

有什么区别?为什么它在设备中以默认的色调颜色显示,并在IB中正确显示?

更新

#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

1 个答案:

答案 0 :(得分:0)

问题出在该行

 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]);
}
似乎在init ...方法之前调用了来自IB的setTintColor。