xcode UILabel 以编程方式设置 x,y 坐标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13333822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:38:23  来源:igfitidea点击:

UILabel setting x,y co-ordinates programmatically

xcodeuilabel

提问by Edward Hasted

How to position (x, y)a UILabelprogrammatically within a view, preferably from viewDidLoad? The labelhas an Outletfor it, e.g. myLabel.

如何position (x, y)一个UILabel视图内编程,优选为viewDidLoad?该labelOutlet吧,比如myLabel

回答by Kamar Shad

Here you can adjust the position of UILabel. In viewWillAppearmethod you just need to change the origin of UILabel as below.

在这里您可以调整 的位置UILabel。在viewWillAppear方法中,您只需要更改 UILabel 的原点,如下所示。

     CGRect frame = myLabel.frame;
     frame.origin.y=10;//pass the Y cordinate 
     frame.origin.x= 12;//pass the X cordinate
     myLabel.frame= frame;

I hope it clears you.

我希望它清除你。

回答by sacred

[label setFrame:CGRectMake(10,20,100,200)];

回答by Majster

Instead of setting the frame you can use just setCenter(x, y).

您可以只使用setCenter(x, y).

Eg: myLabel.center = CGPointMake(x,y);.

例如:myLabel.center = CGPointMake(x,y);

Here you just need to pass the points at where you want to put UIlabelinside the UIView.

在这里,你只需要在想要把传递点UIlabelUIView