Changing the alpha inside UIScrollView

点点圈 提交于 2019-12-11 11:16:46

问题


I was trying to achieve the effect of having my text fade in and out to show there is more data in the UIScrollView in this post: UIScrollView, showing that there is more data by fading out text

I could not get the CAGradientLayer to look right since my background isn't a simple black and white background and I couldn't get it to match and make it look like the text is fading. So I thought I'd try setting the alpha property inside the UIScrollView, or the UILabel's alpha inside the UIScrollView. However, it changes all the text's alpha. Is there a way to do it for only a portion of the text, or a portion of the scrollView? Thanks!


回答1:


There are several ways, at least two of which are reasonably easy:

  1. Create a copy of your background with "feathered" edges. Stick this in a view on top of the scroll view.
  2. Set view.layer.maskLayer on an appropriate view (a UIView containing the scroll view should work) to something suitable (e.g. a CALayer with contents/contentsScale/contentsCenter set appropriately). More of a pain, since CALayer does not autosize itself (so your wrapper view will have to do the necessary things in -setFrame:/-setBounds:/-layoutSubviews). You'll need to #include <QuartzCore/CALayer.h>.


来源:https://stackoverflow.com/questions/6388262/changing-the-alpha-inside-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!