2012-06-28 100 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值,您還必須處理標籤的寬度和高度。