2010-10-05 68 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