views:

113

answers:

1

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];  
+1  A: 

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 http://stackoverflow.com/questions/349858/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.

Peter DeWeese
See my edit above. Adding a xib sounds great, can you give me the code for that ? Also what about linking up the buttons and making sure there nothing underneath the nib on the action sheet ?
Jules
I found this http://stackoverflow.com/questions/2616047/how-to-display-custom-view-in-uiactionsheet but the ActionSheetController is missing
Jules
Peter can you offer any more help ?
Jules
Sorry I had a busy day! I added a few details. Once you are using this view, you can treat it just like your main controller view as far as actions and such are concerned. The offset step of pickerRect.origin.y should be able to place the view in the action sheet, but I did it from memory so you might need to tweak it. Let me know how it goes!
Peter DeWeese
And as for the button, try placing it at 0,0 to start to see where it is, and then offset it once you see it. Also, you'll need to set the bounds of menu like I did in the example.
Peter DeWeese