-2
比方說,我有在Objective-C如何在Swift中設置UIBezierPath的UIColor?
- (void)drawRect:(CGRect)rect {
if (1 < [_points count]) {
UIBezierPath *path = [UIBezierPath bezierPath];
[path setLineWidth:3.];
MyPoint *point = _points[0];
[path moveToPoint:point.where];
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
for (int i = 1; i < (int)_points.count; ++i) {
point = _points[i];
[path addLineToPoint:point.where];
float alpha = 1;
if (1 < now - point.when) {
alpha = 1 - MIN(1, now - (1+point.when));
}
[[UIColor colorWithWhite:0 alpha:alpha] set]; //THIS LINE
[path stroke];
path = [UIBezierPath bezierPath];
[path setLineWidth:3.];
[path moveToPoint:point.where];
}
}
}
我會怎麼做下面的行[[UIColor colorWithWhite:0 alpha:alpha] set];
斯威夫特這樣的事情?