Problem in UIActionSheet in iOS7

Maico2007Maico2007 MXMember ✭✭
edited October 2013 in Xamarin.iOS

I have a question about the use of UIActionSheet in iOS7,

I use UIActionSheet to show options in my application, but now to update the iOS7 when I show more than 20 items that are visible on the screen of the iPad, the rest of the elements overlap the text and not allow me to choose the right, you will have some solution for these cases and not having to keep UITableViewSource.

I use the following code:

List<int> list = Enumerable.Range (1, 30).ToList ();
UIActionSheet actionSheet = new UIActionSheet ();
foreach(var fila in list)
{
   actionSheet.Add (fila.ToString());
}
actionSheet.Title = "Numbers";
actionSheet.Add ("Cancel");
actionSheet.CancelButtonIndex = 30;
actionSheet.Style = UIActionSheetStyle.BlackOpaque;
actionSheet.ShowInView(this.View);
actionSheet.Clicked += delegate(object sender2, UIButtonEventArgs e2) 
{
    if (e2.ButtonIndex==-1 || e2.ButtonIndex==30)
    {

    } 
    else
    {
        new UIAlertView("Selected:",list[e2.ButtonIndex].ToString(),null,"Ok").Show();
    } 
};

Posts

  • SebastienPouliotSebastienPouliot CAXamarin Team Xamurai

    That look similar to this question so you might want to try the suggested workaround (i.e. set the background to white, I assume the issue is the default background is transparent).

  • Maico2007Maico2007 MXMember ✭✭

    Thanks Sebastien.

    I try to change the background color but the same thing keeps happening.

    actionSheet.Style = UIActionSheetStyle.Automatic;
    actionSheet.BackgroundColor = UIColor.White;
    actionSheet.TintColor = UIColor.White;
    actionSheet.TintColorDidChange ();
    actionSheet.ShowInView(this.View);
    
  • SebastienPouliotSebastienPouliot CAXamarin Team Xamurai

    That's likely because your code is not identical to the workaround I linked to. The workaround iterates all subviews to ensure their background color is white. It also does so just before presenting itself (when the subviews are created).

    I tried (simulator only) your code above and did not get the same result - so there might be something else that makes this happen only in certain cases. Anyway I can't confirm it but this C# snippet would match the workaround:

    actionSheet.WillPresent += (object sender, EventArgs e) => {
        actionSheet.BackgroundColor = UIColor.White;
        foreach (var v in actionSheet.Subviews)
            v.BackgroundColor = UIColor.White;
    };
    
  • Maico2007Maico2007 MXMember ✭✭

    Oh great!

    I get it, change the color to each element containing the UIActionSheet

    Thank you.

  • Prajakta.ShindePrajakta.Shinde INUniversity ✭✭✭

    @SebastienPouliot said:
    That's likely because your code is not identical to the workaround I linked to. The workaround iterates all subviews to ensure their background color is white. It also does so just before presenting itself (when the subviews are created).

    I tried (simulator only) your code above and did not get the same result - so there might be something else that makes this happen only in certain cases. Anyway I can't confirm it but this C# snippet would match the workaround:

    actionSheet.WillPresent += (object sender, EventArgs e) => {
    actionSheet.BackgroundColor = UIColor.White;
    foreach (var v in actionSheet.Subviews)
    v.BackgroundColor = UIColor.White;
    };

    @SebastienPouliot
    How can I do this in xamarin.forms?

  • Maico2007Maico2007 MXMember ✭✭

    You can review the following to use native iOS controls, but UIActionSheet is deprecated.

    https://blog.xamarin.com/embedding-native-controls-into-xamarin-forms/

    The most similar in forms is to use Picker

    https://developer.xamarin.com/api/type/Xamarin.Forms.Picker/

Sign In or Register to comment.