0

如果你想创建一个 ImageView,那么你需要像这样创建它:

    UIImageView *imgView = [[[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 20)] autorelease];

x 和 y 坐标是 10,但是如果你有一个标签或其他东西(一个你不知道文本有多长的文本视图)在同一个地方怎么办。你怎么能把它总是显示在标签下的图像,而不是给出坐标你能做什么?

4

3 回答 3

2

为此,您可以采取两种方式。

1.将您的图像视图添加到您的视图中,然后将标签或任何内容添加到您的视图中,然后它会与图像视图重叠,但会给出backGroundColor清晰的颜色。

2.将该标签添加到imageview并将imageview添加到Self.view。

IMP:清除backGroundColor放置在UIImageView.

于 2013-03-15T13:37:14.550 回答
1

设置高度和宽度也等于UILabel

UIImageView *imgView = [[[UIImageView alloc] initWithFrame:CGRectMake(yourLabel.frame.origin.x, yourLabel.frame.origin.y, yourLabel.frame.size.width,yourLabel.frame.size.height)] autorelease];
[self addSubview:imgView];
[self addSubview:yourLabel];
于 2013-03-15T13:48:45.990 回答
1
UIImageView *imgView = [[[UIImageView alloc] initWithFrame:CGRectMake(_yourLabel.frame.origin.x, _yourLabel.frame.origin.y, 100, 20)] autorelease];

然后 :

[yourView addSubview:imgView];
[yourView addSubview:_yourLabel];
于 2013-03-15T13:38:30.263 回答