I am trying to programatically add a gradient layer to a UIButton which was initially created in Interface Builder. I added the new gradient layer in the viewDidLoad method of the ViewController. I have no issues in adding the gradient.
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.btn.layer.bounds;
gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor topGradient] CGColor],(id)[[UIColor bottomGradient] CGColor], nil];
[self.btn.layer insertSublayer:gradientLayer atIndex:0];
The problem is : I am getting the frame from the button created in IB which was laid out with iPhone 4 screen size. All the resize masks are set and work properly and the button on screen on the iPhone 5 simulator is the correct size.
However the gradient applied, only partially fills the button as it is applied to the original frame. How do I get the frame AFTER it has had the autoresizemasks applied to it?
Thanks
had to add this in viewWillAppear