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
I had the same problem. I made this method to get a reference for the shape layer and or generate it if it wasn't there. This method makes sure to throw that layer in the back so that it doesn't cover the label text layer. Just use this and you should be all good, no extra subclasses required.
- (CAShapeLayer*) getShapeLayerForObject: (UIView*) object{
CAShapeLayer *maskLayer;
int loc = -1;
for(int x = 0; x < object.layer.sublayers.count; x++){
if([[object.layer.sublayers objectAtIndex:x] isKindOfClass:[CAShapeLayer class]]){
loc = x;
break;
}
}
if(loc > -1){
maskLayer = (CAShapeLayer*) [object.layer.sublayers objectAtIndex:loc];
}else{
maskLayer = [[CAShapeLayer alloc] init];
[object.layer insertSublayer:maskLayer atIndex:0];
}
return maskLayer;
}