3

我想让我的操作表按钮中的文本的字体大小更小,因为我的文本比宽度长。

如何使字体变小?

我猜你可以将诸如选择器视图之类的东西添加到操作表中,我可能需要将我自己的按钮添加到操作表中,如果是这样的话怎么办?

我需要一个例子。

编辑:我已经取得了一些进展,但是没有显示实际的按钮,但是当您单击它时,您可以看到它与按钮文本的更改一起工作。

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

1 回答 1

3

您可能可以直接执行此操作,但请注意,操作表按钮不是标准 UIButton,而是它们自己特殊的私有控件子类。出于这个原因,当我需要自定义操作表时,我将自己的自定义子视图添加到 UIActionSheet,然后调整工作表的大小以匹配。缺点是为了匹配外观和感觉,我需要自定义按钮图像背景。我从Fitting a UIDatePicker into a 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。

于 2010-10-05T12:51:46.503 回答