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];
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 ?
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您也许可以直接执行此操作,但请注意,操作表按钮不是标准的 UIButton,而是它们自己的特殊私有控件子类。因此,当我需要自定义操作表时,我将自己的自定义子视图添加到 UIActionSheet 中,然后调整工作表的大小以匹配。缺点是为了匹配外观和感觉,我需要自定义按钮图像背景。我改编了(但没有检查编译器)这个例子 Fitting a UIDatePicker into a UIActionSheet。只需添加 xib 创建的 UIView,而不是选择器。
编辑:要包含 xib 中的子视图,请将 UIView 添加到 xib 的顶层,并将其连接到控制器中的 UIView 属性,就像它是普通的界面组件一样。在您的控制器中,它现在可用。
您还可以正常连接按钮操作,而不是使用操作表回调。您需要在按下后关闭操作表,例如
[myUIActionSheet.dismissWithClickedButtonIndex:0animated:YES];
我认为将其视为模态的也可以,IIRC。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.
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.
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.