iPhone,如何缩小操作表按钮中的字体大小?

发布于 2024-09-25 19:54:10 字数 1469 浏览 2 评论 0原文

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

如何将字体变小?

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

我需要一个例子。

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

        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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

草莓酥 2024-10-02 19:54:10

您也许可以直接执行此操作,但请注意,操作表按钮不是标准的 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 属性,就像它是普通的界面组件一样。在您的控制器中,它现在可用。

alt text

您还可以正常连接按钮操作,而不是使用操作表回调。您需要在按下后关闭操作表,例如 [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.

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.

alt text

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文