2011-02-02 83 views
0

我遇到了UIscroll視圖的一些問題。我已經看過參考條目,但我似乎無法找到如何解決它們。基本上我試圖將一個UIlabel插入到一個尺寸爲320 x 270的滾動視圖中(這個尺寸現在的大小是任意的)。我的問題是,我似乎無法讓UILabel出現在視圖的左上角。UIscrollView定位

detailView.frame = frameDFull; // frameDFull = 320 x 500 

    myView.frame = CGRectMake(0, 150, 320, 270); //myFrame is the scroll view 

    myView.contentMode = UIViewContentModeScaleAspectFit; 
    myView.contentSize = CGSizeMake(320, 270); 

    [self.view addSubview:myView]; 

    //UIView *viewHolder = [[UIView alloc]init]; 


    UILabel *eventDesc = [[UILabel alloc] init]; 


    eventDesc.bounds = CGRectMake(0, 0, 320, 100); 
    //eventDesc.backgroundColor = [UIColor clearColor]; 
    eventDesc.text = @"Appears off the screen partially"; 

    [myView addSubview: eventDesc]; 


    [eventDesc release]; 

我可以說我可能已經忘記了在這裏做點什麼。但我不確定是什麼。我試圖使用內容對齊,看看它本質上是一個UIview,但沒有發生任何事情。

+1

哪一個是滾動視圖?你期望發生什麼?發生了什麼呢? – 2011-02-02 23:13:02

回答

0

嘗試

UILabel *eventDesc = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 100)]; 

更換

UILabel *eventDesc = [[UILabel alloc] init]; 

和刪除你設置的邊界線。你應該使用initWithFrame初始化器來處理任何UIView(及其子類),因爲frame determines the view's location within its superview, while the bounds determines the view's location within itself.

+0

非常感謝你,我知道這是小事。我需要確保記住這一點。 – Ohmnastrum 2011-02-03 00:54:38