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

hontrok

macrumors newbie
Original poster
Nov 14, 2012
5
0
I know, this is a stupid stupid question but after one day trying everything I've seen searching, I am uncapable of moving a UILabel, the code is this one:

CGRect frame = self.label_total.frame;
frame.origin.x = 500; // new x coordinate
frame.origin.y = 500; // new y coordinate
self.label_total.frame = frame;

it works if I insert it in a IBAction, but I want to insert it in viewDidLoad, but It doesnt work. Please help me.
 
Code:
[self.label_total setFrame:CGRectMake(500,500,CGRectGetWidth(self.label_total.frame),CGRectGetHeight(self.label_total.frame))];

Something like that I would do.
Also, are you sure the label is already available in the view did load, did you try.

Code:
NSLog(@"show me the label: %@", self.label_total);
 
I've just tried:

[self.label_total setFrame:CGRectMake(500,500,CGRectGetWidth(self.label_total.frame),CGRectGetHeight(self.label_total.frame))];

but as with my example it works inside an IBAction when I click the button, but if I insert it in viewDidLoad, nothing, arggg

I've insert the NsLog before and after the setFrame and this is the result

2012-11-14 11:54:19.626 mightymaths2[1310:c07] show me the label: <UILabel: 0x937d6d0; frame = (0 0; 0 0); text = '0000'; clipsToBounds = YES; opaque = NO; autoresize = TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x937d760>>
2012-11-14 11:54:19.627 mightymaths2[1310:c07] show me the label: <UILabel: 0x937d6d0; frame = (500 500; 0 0); text = '0000'; clipsToBounds = YES; opaque = NO; autoresize = TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x937d760>>

Any ideas please?
 
show me the label: <UILabel: 0x937d6d0; frame = (0 0; 0 0); text = '0000'; clipsToBounds = YES; opaque = NO; autoresize = TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x937d760>>
Here you can obviously see that your frame is 0,0,0,0, so it's not even on screen..
When you make the label, do you set an given frame for it? I don't really understand the issue :s

What do you want to achieve, have an label from XIB or made by code have a certain frame on viewDidLoad?
 
Sorry I didn't mention that the UILabel is on the storyboard


What I want to do is: I have a UILabel on the storyboard, but according some factor, it has to appear in deifferents places, ¿do I explain right?

and sorry for my ignorance
 
Code:
[self.label_total setFrame:CGRectMake(500,500,CGRectGetWidth(self.label_total.frame),CGRectGetHeight(self.label_total.frame))];

Something like that I would do.

That's basically exactly equivalent to what the OP posted, except more complicated and harder to read ;)

----------

it works if I insert it in a IBAction, but I want to insert it in viewDidLoad, but It doesnt work. Please help me.

This is a guess, but I suspect that it doesn't work in viewDidLoad because the storyboard layout is occurring after viewDidLoad is called.

You could try it in viewWillAppear: instead?

Or, perhaps, turn off "Use Autolayout" for your view controller in interface builder?
 
Last edited:
Yesssssssss!!!!!!!

It was the Auto Layout, how stupid I am!!


Thank you very very very much and sorry again for my ignorance
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.