Objective C - CAGradientLayer covers the text in UILabel?

后端 未结 3 1083
星月不相逢
星月不相逢 2021-02-13 19:06

I am trying to add a gradient layet to my UILabel for some reasons the CAGradientLayer covers my text. Am I doing anything wrong

- (voi         


        
3条回答
  •  误落风尘
    2021-02-13 19:58

    The CAGradientLayer is covering the text of your label because the text is drawn by the content of the super layer that you explicitly covered by adding a sublayer.

    Your easiest solution is to use two views. A UIView subclass where you override +[UIView layerClass] and return a [CAGradientLayer]. Add a good init method to setup your gradient.

    Next pup add the UILabel as a subview of your custom gradient view.

提交回复
热议问题