簡體   English   中英

IB_DESIGNABLE tintColor問題

[英]IB_DESIGNABLE tintColor issues

我正在學習IB_DESIGNABLE,但偶然發現了一個問題。

當我使用IB設置自定義視圖的tintColor時,它將在IB中以正確的方式呈現。

在此處輸入圖片說明

但是,當我在設備上運行它時,它將以默認的tintColor顯示。

在此處輸入圖片說明

#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

問題就在那條線上

 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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM