UITextView iPhone中的渐变效果? [英] Gradient effect in UITextView iPhone?

查看:45
本文介绍了UITextView iPhone中的渐变效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个需要在UITextView中实现中心渐变的项目中.它一定是类似附件的图像.我不能在UITextView的顶部使用任何图像,因为我希望在UITextView中进行用户交互.请提供您的建议.谢谢

I am working on a project where I need to implement center gradient in UITextView. It must be something like attached image. I cannot use any image at upper of UITextView because I want user interaction in UITextView. Please provide your suggestions. Thanks

推荐答案

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

If you apply CAGRradient Layer on UITextView and set [txtView.layer setMask:gradient] this will create problem while scrolling means the gradient layer will scroll. To overcome from this problem you must use a UiView working as a container view for your textView. first of all add your container view and then add your text view as subview in your container view. and then use this code which save my life.

 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用作容器视图.这是我的输出.

where view_bottomMenu is UIView working as container view.here is my output.

这篇关于UITextView iPhone中的渐变效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆