Here is a strange thing, but I couldn't figure it out. I can not programmatically set frame for the button.
I have a button with IBOutlet as beyondViewButton and I control-dragged it from view to the ViewController.m file @interface and @end section, then @synthesized it.
in the viewDidLoad method, I added this:
//x = x + widthToUse * 0.25;
//y += h + 50;
x = 50; //either hard code x value or set it mathematically, not working
y = 300;
w = 200;
h = 60;
//[beyondViewButton setFrame:CGRectMake(x, y, w, h)]; //not working
beyondViewButton.frame = CGRectMake(x, y, w, h); //not working
//[beyondViewButton setBackgroundImage:[UIImage imageNamed:@"bgImage.png"] forState:UIControlStateNormal]; //this line actually works
//[beyondViewButton setTitle:@"iCool!" forState:UIControlStateNormal];
[beyondViewButton setTitle:@"iShit!" forState:UIControlStateNormal]; //change from iCool to iShit, I can see change
//[self.view addSubview:beyondViewButton]; //either adding this line or not, both work
Why I can not set up the frame?
One thing, I don't know if relevant, is that this button was set up in the "selection view" which comes from Navigation controller and goes to next view/scene. When this button is clicked, app moves from the "selection view" to the next view --- this was implemented via storyboard. I have not mastered storyboard well yet and have lots of uncertainty about it.
Can anyone shed some lights on this? Thanks!!
More diagnosis info: I checked the button.description before and after I set frame code:
2012[25830:12503] beyond button <UIRoundedRectButton: 0x8821cd0; frame = (0 0; 0 0); opaque = NO; autoresize = TM+BM; layer = <CALayer: 0x8821da0>>
that's before and following is after. Interestingly, the frame values are not what I set, as in code shown here, I have x=50, y=300, w=200, h=60, while NSLog desc