【问题标题】:Gradient effect in UITextView iPhone?UITextView iPhone中的渐变效果?
【发布时间】:2013-08-21 10:33:32
【问题描述】:

我正在做一个需要在 UITextView 中实现中心渐变的项目。它必须类似于附加图像。我不能在 UITextView 上方使用任何图像,因为我希望在 UITextView 中进行用户交互。请提供您的建议。谢谢

【问题讨论】:

  • 你试过使用 nsmutablestring 吗?
  • @IronManGill 这应该是用户可以更改文本并上下滚动的 UITtextview。我应该可以对 NSMutableString 做同样的事情吗?

标签: iphone ios uitextview gradient


【解决方案1】:

如果您在 UITextView 上应用 CAGRradient 层并设置 [txtView.layer setMask:gradient] 这将产生问题,而滚动意味着渐变层将滚动。 要克服这个问题,您必须使用 UiView 作为 textView 的容器视图。首先添加您的容器视图,然后将您的文本视图添加为容器视图中的子视图。然后使用此代码来挽救我的生命。

 CAGradientLayer  gradient = [CAGradientLayer layer];
    gradient.frame = view_bottomMenu.bounds;
    gradient.colors = [NSArray arrayWithObjects:(id)[[[UIColor blackColor colorWithAlphaComponent:0.2] CGColor],(id)[[[UIColor blackColor] colorWithAlphaComponent:0.3] CGColor],(id)[[[UIColor blackColor] colorWithAlphaComponent:0.3] CGColor],(id)[[[UIColor blackColor] colorWithAlphaComponent:0.3] CGColor],  (id)[[[UIColor clearColor] colorWithAlphaComponent:1.0] CGColor], (id)[[[UIColor blackColor] colorWithAlphaComponent:0.3] CGColor],(id)[[[UIColor blackColor] colorWithAlphaComponent:0.3] CGColor],(id)[[[UIColor blackColor] colorWithAlphaComponent:0.3] CGColor],
                       (id)[[[UIColor blackColor] colorWithAlphaComponent:0.2] CGColor], nil];

    gradient.startPoint = CGPointMake(0.0f,0.0f);
    gradient.endPoint = CGPointMake(0.0f, 1.0f);

    [view_bottomMenu.layer setMask:gradient];

view_bottomMenu 是 UIView 作为容器视图工作的地方。这是我的输出。

【讨论】:

    【解决方案2】:

    为了实现这种效果,您必须在 UItextView 上实现 ma​​sking。请检查

    Applying CAGradient mask layer to UITextView

    这显示了如何更改颜色和淡化UITextView 的某些部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      • 2014-11-19
      • 1970-01-01
      • 2015-02-20
      • 1970-01-01
      相关资源
      最近更新 更多