iphone - Gradient layer not showing up/working on an existing View -


I have a view in which it is called another view (swipeview) inside it, I try to paint the gradient using CAGradientLayer I am doing - the code is below

  CAGradientLayer * layer = [CagradientLayer layer]; Layer.colors = [NSArray arrayWithObjects: (ID) [UIColor darkGrayColor] .CGColor, [UIColor lightGrayColor] .CGColor, zero]; Layer. Frame = swipe view. Bound; [Swipeview.layer insertSublayer: Layer atIndex: 0];  

I'm calling it in the ViewDidLoad method of the main view controller. I do not see any effect - the scene I'm trying to paint is that what I am doing wrong? Is there any other settings / orders etc. I should be aware of?

I do not know what this is happening to you is this problem, but only me I was facing, and after a few hours, I searched for my problem: I was making a button, which was adding the gradient layer, initially, the button dimensions are all 0. And when set layer.frame = swipeview.bounds; I was also setting the gradient layer to 0 dimensions. I added the code so that after shaping the button, I also brought the size of the sailors to match and fixed the problem. I am actually using monochach, so the code looks like this:

< Pre> btn.frame = new rectangle ([required dimension]); Fora (var s in BTN layer stallers) {s.Fraame = btn.bounds; }

Perhaps you are creating a view in the code, and there is no visible size or position, and when you add gradient, it does not even resize, and that's why you Can not see when the size of the scene (in ViewDidLayoutSubviews ) changes, change the size of the gradient layer and see if it resolves.


Comments