2010-03-20 57 views
0

我需要在用戶點擊按鈕時顯示帶有UISwitch的「彈出」按鈕,並在點擊彈出窗口中的完成按鈕時保存開關的狀態。UIActionSheet中的控件定位錯誤

於是我就用UIActionSheet做到這一點 - 這一切

sheet = [[UIActionSheet alloc] initWithTitle:@"Switch Setting" 
               delegate:self 
            cancelButtonTitle:nil 
           destructiveButtonTitle:nil 
            otherButtonTitles:@"Done", nil]; 

theSwitch = [[UISwitch alloc] init]; 
[sheet addSubview:theSwitch]; 
[sheet showInView:self.view]; 


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == actionSheet.firstOtherButtonIndex) 
    { 
     theSwitch .on? NSLog(@"Switch is on") : NSLog(@"Switch if off"); 
    } 
} 

的偉大工程。我有定位問題。不幸的是,我現在沒有屏幕截圖在這裏發佈。但是開關出現在操作表標題的同一行的最上方,然後在下方顯示完成按鈕。

請別人幫助我如何將開關置於標題下方並增加操作表尺寸,使其看起來整潔。我需要這個儘快。謝謝。

回答

0

您可以設置交換機的幀。

要在警報視圖

theSwitch = [[UISwitch alloc] init]; 
[sheet addSubview:theSwitch]; 
[sheet showInView:self.view]; 

// get the dimension of the sheet to position the switch 
CGSize parentSize = sheet.frame.size; 
CGRect rect = theSwitch.frame; 
rect.origin.x = parentSize.width/2.0 - rect.size.width; 
rect.origin.y = parentSize.height - rect.size.height - <some space from the bottom>; 
theSwitch.frame = rect; 

是很重要的中間位置的開關,你叫showInView的表後開關的位置。否則,該表的大小爲零。如果替換,可以在底部添加相同的空間。

希望這有助於

0

我認爲你必須通過修改UISwitch像上述trumi框架做它的選項。如果你想放置一個UIButton與他們的圖像here是一個未公開的選項。無證件,因此有被拒絕的風險。

另外你還會發現很多其他的美化選項same thread