Скругленный прямоугольник с градиентом цвета
Я не очень много программировал с Core Graphics. И я склонен придерживаться QuartzCore теперь, когда он делает многое из того, что мне нужно, через свойство layer :)
Тем не менее, у меня есть UIView, который в настоящее время градиент. Я хотел бы добавить закругленные углы к этому UIView, и свойство layer не делает этого, когда я рисую градиент:
- (void)drawRect:(CGRect)rect {
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGGradientRef glossGradient;
CGColorSpaceRef rgbColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = { 1.0, 1.0, 1.0, 0.95, // Start color
1.0, 1.0, 1.0, 0.60 }; // End color
rgbColorspace = CGColorSpaceCreateDeviceRGB();
glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
CGRect currentBounds = self.bounds;
CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), 0.0f);
CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMaxY(currentBounds));
CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, 0);
CGGradientRelease(glossGradient);
CGColorSpaceRelease(rgbColorspace);
}
Я не совсем уверен, где мне следует округлять в методе drawRect. Благодарю.