2012-06-15 36 views
1

我正在使用三個按鈕更改,取消和完成以及在標題的地方顯示UIActionsheet的項目,我希望將UIView包含一些標籤。我創建了動態UIView,並將其添加到動作表中,但隱藏在按鈕後面,我嘗試了所有可能的方法來設置框架,但我無法找到解決方案。我想把這個UIView放在UIActionsheet的頂部,然後是按鈕。如果您有任何疑問,請隨時發表評論。在UIActionSheet中添加UIView作爲子視圖

這裏是我的代碼:

-(IBAction)tapbutton:(id)sender 
{ 
Lablesubview *view = [[Lablesubview alloc]init]; 
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
               delegate:self 
             cancelButtonTitle:@"Cancel" 
           destructiveButtonTitle:@"Change" 
             otherButtonTitles:@"Done",nil]; 

    [actionSheet addSubview:view]; 
    [actionSheet showInView:self.view]; 
} 

回答

3

您可以使用此方法,將100個像素向下移動所有的按鈕,請注意,這種類型的modificaiton可能導致您的申請遭拒

-(IBAction)tapbutton:(id)sender 
{ 
    //create the view 
    Lablesubview *view = [[Lablesubview alloc]init]; 
    //Set the frame 
    view.frame = CGRectMake(0, 10, 320, 100); 
    view.backgroundColor = [UIColor greenColor]; 

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                  delegate:self 
                cancelButtonTitle:@"Cancel" 
               destructiveButtonTitle:@"Change" 
                otherButtonTitles:@"Done",nil]; 

    [actionSheet showInView:self.view]; 

    CGRect rect; 

    //expand the action sheet 
    rect = actionSheet.frame; 
    rect.size.height +=100; 
    rect.origin.y -= 100; 
    actionSheet.frame = rect; 

    //Displace all buttons 
    for (UIView *vButton in actionSheet.subviews) { 
     rect = vButton.frame; 
     rect.origin.y += 100; 
     vButton.frame = rect; 
    }  


    //Add the new view 
    [actionSheet addSubview:view]; 
} 
+0

非常感謝。我只是想在按鈕上方顯示五個標籤,爲此我選擇了這個解決方案,但是如果您說它可能會導致應用程序拒絕,那麼在不會變成拒絕的情況下,可以通過什麼方式實現此目的。 – iMash

+1

創建你自己的視圖添加你自己的標籤和按鈕,然後在屏幕上顯示[self.view addSubView:yourView]; –

+1

其實我已經做了你在上面評論中所說的。無論如何它得到了你的確認。感謝寶貴的指導。 – iMash

相關問題