Can't move a IBOutlet UILabel position

Discussion in 'iOS Programming' started by hontrok, Nov 14, 2012.

  1. hontrok macrumors newbie

    Joined:
    Nov 14, 2012
    #1
    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.
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    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);
     
  3. hontrok thread starter macrumors newbie

    Joined:
    Nov 14, 2012
    #3
    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?
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    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?
     
  5. hontrok thread starter macrumors newbie

    Joined:
    Nov 14, 2012
    #5
    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
     
  6. Reason077, Nov 14, 2012
    Last edited: Nov 14, 2012

    Reason077 macrumors 68000

    Reason077

    Joined:
    Aug 14, 2007
    #6
    That's basically exactly equivalent to what the OP posted, except more complicated and harder to read ;)

    ----------

    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?
     
  7. hontrok, Nov 14, 2012
    Last edited: Nov 14, 2012

    hontrok thread starter macrumors newbie

    Joined:
    Nov 14, 2012
    #7
    Yesssssssss!!!!!!!

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


    Thank you very very very much and sorry again for my ignorance
     

Share This Page