I want to make the font size smaller for the text in the buttons of my action sheet as my text is longer than the width.
我想让字体大小为我的行动表的按钮中的文本,因为我的文本比宽度长。
How can I make the font size smaller?
如何使字体尺寸更小?
I'm guessing as you can add things like picker views to action sheets that I may need to add my own buttons to the action sheet, if so how ?
我猜您可以在动作表中添加picker视图之类的东西,如果可以,我可能需要在动作表中添加我自己的按钮。
I need an example.
我需要一个例子。
EDIT: I've made a little progress, but the actual button isn't shown, but you can see it working with the change in the button text when you click on it.
编辑:我已经取得了一些进展,但是实际的按钮并没有显示出来,但是当你点击它时,你可以看到它与按钮文本中的更改一起工作。
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 个解决方案
#1
3
You may be able to do this directly, but note that actionsheet buttons are not standard UIButtons, but are their own special private control subclass. For this reason, when I need to customize an action sheet, I add my own custom subview to the UIActionSheet and then resize the sheet to match. The downside is that to match the look and feel I need a custom button image background. I adapted (but didn't check in a compiler) this example from Fitting a UIDatePicker into a UIActionSheet. Instead of the picker, just add your xib created UIView.
您可以直接这样做,但是请注意,actionsheet按钮不是标准的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];
EDIT: To include a subview from a xib, add a UIView to the top level of the xib and wire it to a UIView property in your controller just as if it was a normal interface component. Within your controller, it will now be available.
编辑:要包含来自xib的子视图,将UIView添加到xib的顶层,并将其连接到控制器中的UIView属性,就像它是一个普通的接口组件一样。在您的控制器中,它现在是可用的。
You can also wire button actions normally instead of using the action sheet callback. You will need to close the action sheet after the press with something like [myUIActionSheet.dismissWithClickedButtonIndex:0 animated:YES];
I think that dismissing it as if it is modal will also work, IIRC.
您还可以正常地连接按钮操作,而不是使用操作表回调。您将需要在按下之后使用类似[myUIActionSheet]的东西来关闭动作表单。dismissWithClickedButtonIndex:0动画:是的);我认为把它看成是模态的也可以,IIRC。
#1
3
You may be able to do this directly, but note that actionsheet buttons are not standard UIButtons, but are their own special private control subclass. For this reason, when I need to customize an action sheet, I add my own custom subview to the UIActionSheet and then resize the sheet to match. The downside is that to match the look and feel I need a custom button image background. I adapted (but didn't check in a compiler) this example from Fitting a UIDatePicker into a UIActionSheet. Instead of the picker, just add your xib created UIView.
您可以直接这样做,但是请注意,actionsheet按钮不是标准的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];
EDIT: To include a subview from a xib, add a UIView to the top level of the xib and wire it to a UIView property in your controller just as if it was a normal interface component. Within your controller, it will now be available.
编辑:要包含来自xib的子视图,将UIView添加到xib的顶层,并将其连接到控制器中的UIView属性,就像它是一个普通的接口组件一样。在您的控制器中,它现在是可用的。
You can also wire button actions normally instead of using the action sheet callback. You will need to close the action sheet after the press with something like [myUIActionSheet.dismissWithClickedButtonIndex:0 animated:YES];
I think that dismissing it as if it is modal will also work, IIRC.
您还可以正常地连接按钮操作,而不是使用操作表回调。您将需要在按下之后使用类似[myUIActionSheet]的东西来关闭动作表单。dismissWithClickedButtonIndex:0动画:是的);我认为把它看成是模态的也可以,IIRC。