0

I'm new to x-code and I am trying to set the x,y position of a UILabel but I can't figure out why it is not working.

.h

@interface ViewController:UIViewController{
     IBOutlet UILabel *badgeslabel;
}
@property (nonatomic,retain)IBOutlet UILabel *badgeslabel;
@end

.m

@implementation ViewController
@synthesize badgeslabel;

-(void)setBadge{
    [badgeslabel setAlpha:.5];
    [badgeslabel setCenter:CGPointMake(160,30)];
}

The setAlpha works, but the setCenter don't. Also, when I put the code in an IBAction the setCenter works but I don't know why. I'm on xcode 5.0 Any help is appreciated, thank you.

Caetano
  • 25
  • 5
  • 2
    Is autolayout turned on? That's usually the issue. Also, in your .m the label name is plural (different name). Typo? – Joel Oct 22 '13 at 15:55
  • In my code the name of the label was correct, i just typo when i transcript to here, it's edited now. About the autolayout I don't know how to check that – Caetano Oct 22 '13 at 16:03
  • http://stackoverflow.com/questions/9566789/remove-autolayout-constraints-in-interface-builder – Joel Oct 22 '13 at 16:07
  • That made it right, it works now. Many thanks. – Caetano Oct 22 '13 at 16:15

1 Answers1

0

As stated by Joel, if you have autolayout enabled then XCode won't allow you to manually set the x & y values of UIViews within a view controller because they are using constraints, attempting to do this will most likely break any constraints you have setup or XCode has added automatically and distort the position of any other UIViews you have in your View Controller.

If you don't want to use autolayout then simply disable it by going to the File inspector in interface builder (click your storyboard file), and untick "Use Auto Layout". This will revert to the old "Spring & Struts" way of laying out and allow you to set the position of your UIViews in code.

Darryl Bayliss
  • 2,677
  • 2
  • 19
  • 28