簡體   English   中英

iPhone,如何在動作表按鈕中縮小字體?

[英]iPhone, how can I make the font size smaller in actionsheet buttons?

我希望使我的操作表按鈕中的文本字體更小,因為我的文本比寬度長。

如何縮小字體?

我猜你可以在行動表中添加選擇器視圖之類的東西,我可能需要將自己的按鈕添加到操作表中,如果是這樣的話怎么辦?

我需要一個例子。

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

        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];  

您可以直接執行此操作,但請注意,操作表按鈕不是標准UIButtons,而是它們自己的特殊私有控件子類。 出於這個原因,當我需要自定義一個操作表時,我將自己的自定義子視圖添加到UIActionSheet,然后調整工作表的大小以匹配。 缺點是要匹配外觀我需要一個自定義按鈕圖像背景。 我通過將UIDatePicker安裝到UIActionSheet中來修改(但沒有檢入編譯器)這個例子。 而不是選擇器,只需添加你的xib創建的UIView。

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];

編輯:要包含xib的子視圖,請將UIView添加到xib的頂層,並將其連接到控制器中的UIView屬性,就像它是一個普通的接口組件一樣。 在您的控制器中,它現在可用。

替代文字

您還可以正常連接按鈕操作,而不是使用操作表回調。 您需要在按下后關閉操作表,例如[myUIActionSheet.dismissWithClickedButtonIndex:0 animated:YES]; 我認為將它視為模態也是有效的,IIRC。

暫無
暫無

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

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