Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kozer

macrumors newbie
Original poster
Aug 8, 2016
1
0
I have a xib file which has a contain one uiview and 3 uibutton. flush-seamed spaced.(uiview 2px space uibuttun 2px space ...)

I apply constraints in xib files and they are automatically right place if device ipad,iphone or landscape or portrait first launching. They are getting bigger or smaller according to device. the problem start when i apply gradient to buttons.
Code:
CAGradientLayer*gradientMain =[CAGradientLayer layer];
gradientMain.frame = myview.frame;//myview.bounds no matter
gradientMain.colors =[NSArray arrayWithObjects:(id)[[UIColor colorWithRed:(65/255.0) green:(64/255.0) blue:(66/255.0) alpha:1.0]CGColor],(id)[[UIColor colorWithRed:(35/255.0)  green:(31/255.0)  blue:(32/255.0)  alpha:1.0]CGColor],nil];
[myview.layer insertSublayer:gradientMain atIndex:0];

afterthis code, when i change orientation of device bounds in xib file sizes and views are conflicting. How can i achive this problem.

İ try to these after orientation, but not work
Code:
[self.centerCollectionView reloadData];
 
Last edited by a moderator:
I haven't messed with layers too much but Mr Google tells me that this is a common issue. The view doesn't keep its gradientLayer's frame in sync. You have to add code to do that. One way is to subclass UIView and implement layoutSubviews and set the gradient layer's frame to self.bounds. You can set the gradient layer's frame in the view controller also if you wish.

See

http://stackoverflow.com/questions/24303279/auto-layout-constraint-on-calayer-ios
http://stackoverflow.com/questions/15581374/how-to-resize-a-cagradientlayer-after-rotation
https://recalll.co/app/?q=ios - Issue adding CAGradientLayer sublayer to UIView

and many other comments.
 
  • Like
Reactions: kozer
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.