【问题标题】:Move UILabel's center up in UIView.在 UIView 中将 UILabel 的中心向上移动。
【发布时间】:2013-06-13 16:52:26
【问题描述】:

我正在尝试创建一个 UILabel,并使用 label.center = view.center 将其设置为视图的中心。但我想将它向上移动 100 像素。

我该怎么做?

类似label.frame = CGRectMake(current-x, 100, 42, 21);

这可能吗?保持x 不变,但更改y

【问题讨论】:

    标签: ios objective-c label cgrectmake


    【解决方案1】:

    执行此操作:label.center = CGPointMake(view.center.x, view.center.y - 100);

    【讨论】:

    • 啊...我不知道CGPointMake,我刚试过label.center = CGRectMake,这给我带来了各种各样的问题,原因很明显。感谢您的帮助。
    • @HenryHarris 欢迎您。如果它解决了您的问题,那么您可以接受答案。:)
    • @RahulV.Mane 不,当您使用视图的中心设置标签的中心时,不需要这样做。只有当您使用视图的高度来设置标签的中心或框架时,您才需要这样做。
    【解决方案2】:
    CGRect frame = view.center;
    frame.origin.x -= 100.0;
    label.frame = frame;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-07
      相关资源
      最近更新 更多