0

我有一个滚动视图(IBOutlet);在那个滚动视图中,我添加了一个图像视图。我正在尝试根据其大小在图像中添加标签。我的意思是,在图像中放置标签有 9 个选项:例如 TR(右上角)、TC(顶部中心)、C(中心)......假设我的图像小于 iPhone 的分辨率,比如 300x160。现在,我正在图像视图中加载标签,但它无法正常工作,标签的对齐方式不正确。这是我的对齐按钮代码:

-(IBAction)btn_AlignPressed:(UIButton*)sender{
    lbl.tag = sender.tag;
    [imgView addSubview:lbl];
    if (sender.tag == 1) {
        lbl.frame = CGRectMake(0, 0, imgView.frame.size.width, imgView.frame.size.height);
    } else if(sender.tag == 2) {
        lbl.frame = CGRectMake(160-(imgView.frame.size.width/2), 0, imgView.frame.size.width, imgView.frame.size.height);
    } else if(sender.tag == 3) {
        lbl.frame = CGRectMake(320-imgView.frame.size.width, 0, imgView.frame.size.width, imgView.frame.size.height);
    } else if(sender.tag == 4) {
        lbl.frame = CGRectMake(0, 210-(imgView.frame.size.height/2), imgView.frame.size.width, imgView.frame.size.height);
    } else if(sender.tag == 5) {
        lbl.frame = CGRectMake(160-(imgView.frame.size.width/2), 210-(imgView.frame.size.height/2), imgView.frame.size.width, imgView.frame.size.height);
    } else if(sender.tag == 6) {
        lbl.frame = CGRectMake(320-imgView.frame.size.width, 210-(imgView.frame.size.height/2), imgView.frame.size.width, imgView.frame.size.height);
    } else if(sender.tag == 7) {
        lbl.frame = CGRectMake(0, 420-imgView.frame.size.height, imgView.frame.size.width, imgView.frame.size.height);
    } else if(sender.tag == 8) {
        lbl.frame = CGRectMake(160-(imgView.frame.size.width/2), 420-imgView.frame.size.height, imgView.frame.size.width, imgView.frame.size.height);
    } else if(sender.tag == 9) {
        lbl.frame = CGRectMake(320-imgView.frame.size.width, 420-imgView.frame.size.height, imgView.frame.size.width, imgView.frame.size.height);
    }
}

请帮我。

提前致谢。

4

1 回答 1

0

您只需设置 x 和 y 值,还必须处理标签的宽度和高度。

于 2012-06-28T06:41:01.323 回答