iPhone,如何在动作表按钮中缩小字体?

时间:2010-10-05 11:55:43

标签: iphone uiactionsheet

我想让我的操作表按钮中的文字缩小字体,因为我的文字长于宽度。

如何缩小字体?

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

我需要一个例子。

编辑:我已经取得了一些进展,但实际的按钮没有显示,但是当你点击它时,你可以看到按钮文字的变化。

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

1 个答案:

答案 0 :(得分:3)

您可以直接执行此操作,但请注意,操作表按钮不是标准UIButtons,而是它们自己的特殊私有控件子类。出于这个原因,当我需要自定义一个操作表时,我将自己的自定义子视图添加到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属性,就像它是普通的接口组件一样。在您的控制器中,它现在可用。

alt text

您也可以正常连接按钮操作,而不是使用操作表回调。你需要在新闻发布后用[myUIActionSheet.dismissWithClickedButtonIndex:0 animated:YES];之类的方式关闭行动表。我认为将其视为模态也是有效的,IIRC。

相关问题