2010-10-05 137 views
3

我想爲我的操作表的按鈕中的文本設置更小的字體,因爲我的文本比寬度更長。iPhone,如何在動作表按鈕中縮小字體大小?

如何縮小字體大小?

我在猜測,你可以添加選擇器視圖到動作表,我可能需要將我自己的按鈕添加到動作表,如果是這樣?

我需要一個例子。

編輯:我已經取得了一些進展,但實際的按鈕沒有顯示,但你可以看到它在點擊按鈕文本時發生改變。

 UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Date Picker" 
                  delegate:self 
               cancelButtonTitle:@"Cancel" 
              destructiveButtonTitle:nil 
               otherButtonTitles:@"OK",nil];  

     CGRect frame = CGRectMake(100.0, 80.0, 100.0, 40.0); 

     UIButton *pickerView = [[UIButton alloc] initWithFrame:frame]; 

     [pickerView setTitle:@"FRED" forState:UIControlStateNormal]; 

     [pickerView setTitle:@"Go Back" forState:UIControlStateNormal]; 
     [pickerView setTitleColor:[UIColor blackColor] forState:UIControlEventTouchDown]; 
     pickerView.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
     pickerView.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
     //[removeButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchDown]; 
     [pickerView setBackgroundColor:[UIColor blueColor]]; 


     [menu addSubview:pickerView]; 
     [menu showInView:self.view];   

     [pickerView release]; 
     [menu release]; 

回答

3

您可能可以直接做到這一點,但請注意,動作表按鈕不是標準的UIButtons,而是它們自己的專用專用控件子類。出於這個原因,當我需要自定義一個操作表時,我將自己的自定義子視圖添加到UIActionSheet中,然後調整表單以匹配。缺點是要匹配外觀和感覺,我需要一個自定義按鈕圖像背景。我從Fitting a UIDatePicker into a UIActionSheet改編(但沒有檢查編譯器)這個例子。而不是選擇器,只需添加您創建的UIView的xib。

UIDatePicker *pickerView = [[UIDatePicker alloc] init]; 
pickerView.datePickerMode = UIDatePickerModeDate; 
[myUIActionSheet addSubview:pickerView]; 
[myUIActionSheet showInView:self.view];   
[myUIActionSheet setBounds:CGRectMake(0,0,320, myUIActionSheet.bounds.size.height + pickerView.bounds.size.height)]; 

CGRect pickerRect = pickerView.bounds; 
pickerRect.origin.y = - pickerView.bounds.size.height; //you may need to change this offset 
pickerView.bounds = pickerRect; 

[pickerView release]; 
[myUIActionSheet release]; 

編輯:要包括從廈門國際銀行子視圖中,添加一個UIView到廈門國際銀行,並將其連接到一個UIView財產在你的控制器頂層就好像它是一個正常的界面組件。在您的控制器中,它現在可用。

alt text

您還可以絲按鈕動作,而不是通常使用的動作片回調。您需要在新聞發佈之後關閉活動頁面,例如[myUIActionSheet.dismissWithClickedButtonIndex:0 animated:YES];我認爲將它視爲模板也是可行的,IIRC。

+0

看到我上面的修改。添加一個xib聽起來不錯,你能給我這個代碼嗎?另外,連接按鈕並確保操作表上的筆尖下面沒有任何東西? – Jules 2010-10-05 12:59:06

+0

我發現這個http://stackoverflow.com/questions/2616047/how-to-display-custom-view-in-uiactionsheet,但ActionSheetController丟失 – Jules 2010-10-05 13:05:22

+0

彼得你能提供更多的幫助嗎? – Jules 2010-10-05 15:01:35