2014-02-16 107 views

回答

0

只需將它包含明確的漸變圖像白色文本視圖的底部頂部的UIImageView。這是我猜測的最簡單的方法。

+0

我想沒有的UIImageView,一些通過的CALayer [不知道] – DAMM108

1

嘗試以下操作:我試着像以下但不UITextView的

UIView *vwTest = [[UIView alloc] initWithFrame:_textView.frame]; 
[vwTest setBackgroundColor:[UIColor whiteColor]]; 
[vwTest setUserInteractionEnabled:NO]; 
[self.view addSubview:vwTest]; 

NSArray *colors = [NSArray arrayWithObjects: 
        (id)[[UIColor colorWithWhite:0 alpha:1] CGColor], 
        (id)[[UIColor colorWithWhite:0 alpha:0] CGColor], 
        nil]; 

CAGradientLayer *layer = [CAGradientLayer layer]; 
[layer setFrame:vwTest.bounds]; 
[layer setColors:colors]; 
[layer setStartPoint:CGPointMake(0.0f, 1.0f)]; 
[layer setEndPoint:CGPointMake(0.0f, 0.6f)]; 
[vwTest.layer setMask:layer]; 
+0

'CAGradientLayer'將做到這一點是肯定的,但不在'textView.layer'上。如果您滾動,則漸變會隨之滾動。我會建議做一些小修改。在'textView'上放置一個'UIView'並掩蓋'UIView'。另外...交換漸變的開始和結束顏色。實際上,如果我更新你的答案,不要介意._ – staticVoidMan

+0

沒問題。一些如何,我們的答案會幫助別人。感謝您的更正:) –

0
let gradientLayer: CAGradientLayer = CAGradientLayer() 
     gradientLayer.frame = CGRectMake(0.0, 0.0, CGRectGetWidth(textView.frame), CGRectGetHeight(textView.frame)) 
     gradientLayer.colors = [UIColor.init(white: 1, alpha: 0).CGColor, UIColor.whiteColor().CGColor] 
     gradientLayer.startPoint = CGPointMake(0, 0.6) 
     gradientLayer.endPoint = CGPointMake(0.0, 1) 
      self.textview.layer.addSublayer(gradientLayer)