2012-06-28 22 views
0

我有一个滚动视图(IBOutlet);在那个scrollview中我添加了一个imageview。我试图根据其大小在图像中添加标签。我的意思是,有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); 
    } 
} 

请帮帮我。

在此先感谢。

回答

0

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