感谢@mackworth为而导致的解决方案
为了完整性,我回答它的建议。
概述:
似乎有一些麻烦,在UITextView
添加子视图,然后使用自动布局。
解决方案:
因此该解决方案是创建HazeView作为一个子视图到的UITextView
的父视图。
步骤:
- 创建
UITextView
- 创建HazeView(亚类从UIView的)
- 作为子视图相同的父视图
- 位置
HazeView
在添加两UITextView
和HazeView
UITextView
的底部
- 确保背景色HazeView的r是对
HazeView
[UIColor clearColor]
- 禁用用户交互最好是创建
UIView
一个子类,并把里面的UITextView
和HazeView
,以便它可以被重用
创建HazeView:
self.hazeView.backgroundColor = [UIColor clearColor];
HazeView
是一个子类210
- (void)drawRect:(CGRect)rect
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *color1 = [UIColor colorWithRed:1.0 green:1.0
blue:1.0 alpha:0.25];
UIColor *color2 = [UIColor colorWithRed:1.0 green:1.0
blue:1.0 alpha:0.5];
UIColor *color3 = [UIColor colorWithRed:1.0 green:1.0
blue:1.0 alpha:0.75];
NSArray *gradientColors = @[(id) color1.CGColor,
(id) color2.CGColor,
(id) color3.CGColor];
CGFloat gradientLocations[] = {0, 0.50, 1};
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) gradientColors, gradientLocations);
CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));
CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
CGGradientRelease(gradient);
}
看到这里可能更好的方法:http://stackoverflow.com/questions/12845590/applying-cagradient-mask-layer-to-uitextview – mackworth
谢谢你的建议导致了最终的解决方案 – user1046037