如何添加漸變背景到UIScrollView?我有一個UIScrollView在其上的viewcontroller。我想爲scrollview添加漸變背景。我也有一個用於背景的漸變圖像,但它並不完全適合滾動視圖的內容大小。漸變背景UIScrollView
請幫忙。 謝謝
如何添加漸變背景到UIScrollView?我有一個UIScrollView在其上的viewcontroller。我想爲scrollview添加漸變背景。我也有一個用於背景的漸變圖像,但它並不完全適合滾動視圖的內容大小。漸變背景UIScrollView
請幫忙。 謝謝
我以前設置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);
}
我不知道什麼樣的影響直接在UIScrollView
的drawRect
將有繪製漸變。
從https://github.com/techiedees/GradientTest鏈接下載示例項目。
其中有TDGradientView框架。只要用它來任何你想要的項目。
您可以在http://www.techiedees.com/2012/04/how-to-create-gradient-view-at-run-time.html