Oh man, I use this a lot. Have it saved as a snippet:
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.textView.superview.bounds;
gradient.colors = @[(id)[UIColor clearColor].CGColor, (id)[UIColor blackColor].CGColor, (id)[UIColor blackColor].CGColor, (id)[UIColor clearColor].CGColor];
gradient.locations = @[@0.0, @0.03, @0.97, @1.0];
self.textView.superview.layer.mask = gradient;
This solution requires that your text view be embedded in a view of its own. This applies a 3% fade to the top and bottom of the text view. Modify gradient.locations
to your needs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…