In my app I am adding gradiant layer on the cell on some condition. In previous versions of iOS it worked fine, but after updating to 14.1 it stopped showing gradiant. Following is the code which is used to show gradiant.
Layer.InsertSublayer(Utility.GetGradientLayer(Frame, GradientColor.Green), 0);
I have tested it on iOS 11 simulator and this code works fine, but for iOS 14 it don't shown on cell. When I change the index from 0 to 1 (as shown below),
Layer.InsertSublayer(Utility.GetGradientLayer(Frame, GradientColor.Green), 1);
the gradiant get shown on iOS 14 device but on iOS-11 device, gradiant layer show in from of the text and the text of the cell get back to this gradiant layer and don't shown (Please note that Layer is a CALayer's object). Any help in this regard will be highly appreciated. Thanks
From the describtion, you could use following ways to solve whether belong to iOS 14 device first:
if (UIDevice.CurrentDevice.CheckSystemVersion(14, 0))
{
Layer.InsertSublayer(Utility.GetGradientLayer(Frame, GradientColor.Green), 1);
}
else
{
Layer.InsertSublayer(Utility.GetGradientLayer(Frame, GradientColor.Green), 0);
}
About the reason, I guess that in iOS 14 device there should be more than one sub-layer, therefore, inset at 0
can not show.
You also could have a try with following ways to check whether can work:
if(Layer.Sublayers.Length > 1)
{
Layer.InsertSublayer(Utility.GetGradientLayer(Frame, GradientColor.Green), 1);
// or try this
Layer.InsertSublayerAbove(Utility.GetGradientLayer(Frame, GradientColor.Green), Layer.Sublayers[0]);
}
else
{
Layer.InsertSublayer(Utility.GetGradientLayer(Frame, GradientColor.Green), 0);
}