iOS*_*Dev 2 iphone objective-c uiscrollview uiviewcontroller ios
如何将渐变背景添加到UIScrollView?我有一个带有UIScrollView的viewcontroller.我想为scrollview添加渐变背景.我也有一个背景渐变图像,但它不完全适合滚动视图的内容大小.
请帮忙.谢谢
我之前设置UIScrollView
backgroundColor
为清除然后在滚动视图后面定位了一个渐变视图.然后绘制一个渐变,UIView
如:
- (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] = { 0.119, 0.164, 0.192, 1.000, // Start color
0.286, 0.300, 0.307, 1.000 }; // 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);
}
Run Code Online (Sandbox Code Playgroud)
我不知道在UIScrollView
s中直接绘制渐变有什么效果drawRect
.