如何使用左侧或右侧移动UILabel? [英] How to move UILabel using left or right side?

查看:58
本文介绍了如何使用左侧或右侧移动UILabel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是XCode/iOS的新手,我想弄清楚如何根据左侧(或右侧)而不是中心移动Label.

I'm new to XCode/iOS and I'm trying to figure out how to move a Label based on the left (or right) side, not the center.

我所能找到的就是这样:

All I can find is something like this:

[myLabel setCenter:CGPointMake(x,y)];

我也看到了这个变体:

myLabel.center=CGPointMake(x,y);

我的问题分为两个部分:

My question has two parts:

  1. 如何执行类似的操作,但不使用标签中心?

  1. How do do something similar, but without using the label center?

.center"是否是 UILabel 对象的属性?例如,在MS/VB/C#/etc中.对象具有用于定位的".left,.right,.top,.bottom"-iOS/Objective-C中是否存在类似内容?

Is ".center" a property of the UILabel object? For example, in MS/VB/C#/etc. objects have ".left, .right, .top, .bottom" for positioning - is there something similar in iOS/Objective-C?

推荐答案

center 是UIView的属性,不,没有等效的 left right或其他任何内容.您需要手动进行计算:标签的左侧是 label.frame.origin.x ,右侧是 label.frame.origin.x + label.frame.size.width.如果您想移动标签以使其与特定坐标右对齐,则可以执行以下操作:

center is a property of UIView, and no, there’s no equivalent left, right, or whatever. You need to do the calculation manually: the label’s left side is label.frame.origin.x and its right side is label.frame.origin.x + label.frame.size.width. If you want to move the label so it’s right-aligned with a particular coordinate, then you can do something like this:

label.frame = CGRectMake(100 - label.frame.size.width, label.frame.origin.y, label.frame.size.width, label.frame.size.height);

这篇关于如何使用左侧或右侧移动UILabel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆