Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在图像视图中对齐标签?_Iphone_Uiimageview_Uilabel - Fatal编程技术网

Iphone 如何在图像视图中对齐标签?

Iphone 如何在图像视图中对齐标签?,iphone,uiimageview,uilabel,Iphone,Uiimageview,Uilabel,我有一个滚动视图(IBOutlet);在这个滚动视图中,我添加了一个imageview。我正在尝试根据图像的大小在图像中添加标签。我的意思是,在图像中放置标签有9个选项:例如TR(右上角)、TC(上中)、C(中)。。。假设我的图像小于iPhone的分辨率,比如300x160。现在,我正在图像视图中加载标签,但工作不正常,标签对齐不正确。 这是我的对齐按钮代码: -(IBAction)btn_AlignPressed:(UIButton*)sender{ lbl.tag = sender.

我有一个滚动视图(IBOutlet);在这个滚动视图中,我添加了一个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);
    }
}
请帮帮我


提前感谢。

您只需设置x和y值,还需要调整标签的宽度和高度