【发布时间】:2015-05-31 12:47:18
【问题描述】:
我正在进入 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];
}
有什么区别?为什么在设备中以默认的tint color显示,而在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
【问题讨论】:
-
我运行了您的代码,它在 IB、模拟器和设备上运行良好。问题一定出在其他地方。也许显示自定义视图的头文件?这是我使用的:
#import <UIKit/UIKit.h> IB_DESIGNABLE @interface Circle : UIView @property (nonatomic) IBInspectable double lineWidth; @property (nonatomic) IBInspectable double startAngleRadians; @property (nonatomic) IBInspectable double endAngleRadians; @end -
@picciano 是的,看起来一样。
标签: ios interface-builder uicolor tintcolor ibdesignable