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.

4

1 回答 1

0

正如 Joel 所说,如果您启用了自动布局,那么 XCode 将不允许您在视图控制器中手动设置 UIViews 的 x 和 y 值,因为它们正在使用约束,尝试这样做很可能会破坏您设置的任何约束或 XCode 已自动添加并扭曲了您在 View Controller 中拥有的任何其他 UIView 的位置。

如果您不想使用自动布局,则只需转到界面构建器中的文件检查器(单击您的故事板文件)将其禁用,然后取消选中“使用自动布局”。这将恢复到旧的“Spring & Struts”布局方式,并允许您在代码中设置 UIView 的位置。

于 2013-10-22T16:20:15.633 回答