设置 TextLabel 位置 Objective-c

发布于 2024-12-09 04:56:05 字数 150 浏览 0 评论 0原文

我有一个滚动视图,其中有许多对象,因为我无法在 InterfaceBuilder 中编辑滚动视图上的位置,我如何通过编程设置对象的位置? 像这样的东西:

myTextField.x = 50;
myTextField.y = 540;

I have a Scroll View with many objects in it,since i cant edit the position on scrollview in InterfaceBuilder,how i set the position of the object programmactily?
Something like:

myTextField.x = 50;
myTextField.y = 540;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木有鱼丸 2024-12-16 04:56:05

使用框架属性将其设置为相对于超级视图的坐标,如下所示:

myTextLabel.frame = CGRectMake(x, y, width, height);

没有文本标签,但我假设您的意思是 UITextFieldUILabel,无论哪种方式都继承自 UIView 并具有框架属性。

Use the frame property to set it relative to the superview's coordinates like this:

myTextLabel.frame = CGRectMake(x, y, width, height);

There is no textlabel but I assume you mean either UITextField or UILabel, either way both inherit from UIView and have the frame property.

溺孤伤于心 2024-12-16 04:56:05

您还可以根据对象的中心移动它。

float x = 220; //Change This Number
float y = 180; //Change This Number

myTextField.center = CGPointMake(x,y);

You could also move it according to the object's center.

float x = 220; //Change This Number
float y = 180; //Change This Number

myTextField.center = CGPointMake(x,y);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文