簡體   English   中英

如何在圖像視圖中對齊標簽?

[英]How to align label in image view?

我有一個滾動視圖(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);
    }
}

請幫我。

提前致謝。

您只需設置x和y值,還必須處理標簽的寬度和高度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM