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
UILabel setting x,y co-ordinates programmatically
提问by Edward Hasted
How to position (x, y)
a UILabel
programmatically within a view, preferably from viewDidLoad
? The label
has an Outlet
for it, e.g. myLabel
.
如何position (x, y)
一个UILabel
视图内编程,优选为viewDidLoad
?该label
有Outlet
吧,比如myLabel
。
回答by Kamar Shad
Here you can adjust the position of UILabel
.
In viewWillAppear
method 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 UIlabel
inside the UIView
.
在这里,你只需要在想要把传递点UIlabel
内UIView
。