Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

How to add an image to a UIActionSheet?

MarcoMarco Posts: 69Registered Users
edited July 2011 in iPhone SDK Development
Is there a way to add an image to a UIActionSheet?

Thank you
Post edited by Marco on
Peace in Christ

Marco Napoli

http://www.ourlovingmother.org

Replies

  • davidlansalotdavidlansalot Posts: 109Registered Users
    edited April 2009
    Marco;77271 said:
    Is there a way to add an image to a UIActionSheet?

    Thank you
    I dont think so
  • MarcoMarco Posts: 69Registered Users
    edited April 2009
    I was afraid of that... bummer.

    Thanks
    Peace in Christ

    Marco Napoli

    http://www.ourlovingmother.org
  • AmanAppsAmanApps Posts: 61Registered Users
    edited July 2009
    Hello Marco,
    You can define this method in UIActionSheet deleget:

    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet{
    UIImageView df = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Someimage.png"]];
    [actionSheet addSubView:df];

    }

    Hope my first post in this forum may come into your helps :)
    iOS application development lead at MobiLab Solutions.

    Expert in Java/Spring/OSGi, iOS app development.

    Enthusiastic C/C++, PHP, Cocoa Mac App developer.
  • funkytacofunkytaco Posts: 412Registered Users
    edited August 2009
    AmanApps;99502 said:
    Hello Marco,
    You can define this method in UIActionSheet deleget:

    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet{
    UIImageView df = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Someimage.png"]];
    [actionSheet addSubView:df];

    }

    Hope my first post in this forum may come into your helps :)
    This code didn't work.
  • AmanAppsAmanApps Posts: 61Registered Users
    edited August 2009
    funkytaco;111992 said:
    This code didn't work.
    Sorry, there is a typo, '*' is missed, plz update the following line:

    UIImageView* df  = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"SomePic.png\"]];


    You may also need to update the frame of the image to position at the desired location and need to add "SomePic.png" as the resource :)

    Thanks.
    iOS application development lead at MobiLab Solutions.

    Expert in Java/Spring/OSGi, iOS app development.

    Enthusiastic C/C++, PHP, Cocoa Mac App developer.
  • funkytacofunkytaco Posts: 412Registered Users
    edited August 2009
    UIImageView *df = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"magnolia.png"]];
    [actionSheet addSubView:df];
    Did you mean to put the asterisk on the df, like the above code?
    2009-08-08 21:51:02.365 WP[8512:20b] *** -[UIActionSheet addSubView:]: unrecognized selector sent to instance 0xf571e0
    2009-08-08 21:51:02.366 WP[8512:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIActionSheet addSubView:]: unrecognized selector sent to instance 0xf571e0'
    Still, didn't work. :)

    Late welcome to the forums, but... welcome to the forums. :)
  • AmanAppsAmanApps Posts: 61Registered Users
    edited August 2009
    funkytaco;112003 said:
    Did you mean to put the asterisk on the df, like the above code?


    Still, didn't work. :)

    Late welcome to the forums, but... welcome to the forums. :)
    Thanks :)

    !! do a clean, then build.

    Or download the demo app from here, just made for you :)

    http://amanpages.com/downloads/ActionSheetTest.zip

    http://amanpages.com/downloads/ActionSheetTest.png (SS)
    iOS application development lead at MobiLab Solutions.

    Expert in Java/Spring/OSGi, iOS app development.

    Enthusiastic C/C++, PHP, Cocoa Mac App developer.
  • funkytacofunkytaco Posts: 412Registered Users
    edited August 2009
    Thanks, I copy & pasted your code and it worked fine?!?!?

    Use my commented version and it will crash? I must be going cross-eyed. :confused:
    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet{

    UIImageView* df = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"magnolia.png"]];
    [actionSheet addSubview:df];

    }

    /**

    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
    UIImageView* df = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"magnolia.png"]];
    [actionSheet addSubView:df];

    } **/
    I don't see the problem....

    I'm gonna bump up your reputation, though. Thanks. Your solution works fine.
  • funkytacofunkytaco Posts: 412Registered Users
    edited August 2009
    This version will resize it as shown. I have no idea how to put it at the top of the action sheet yet, though.

    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet{

    UIImageView* df = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourpic.png"]];
    df.center

    [actionSheet addSubview:df];
    //scale image aspect to fit image view
    df.contentMode = UIViewContentModeScaleAspectFit;
    //change width of frame
    CGRect frame = df.frame;
    frame.size.width = 50;
    df.frame = frame;

    }
  • AmanAppsAmanApps Posts: 61Registered Users
    edited August 2009
    thats really tricky, not only putting any extra view on top, also to receive events.

    I had to put a table view above the buttons. Though I could use a xib to make a view like actions sheet and animate up.

    anyway, to put any image or view above the buttons and receive events, add that view to the actionsheet's superview. Like :


    df.frame = CGRectMake(0, 0, 320, 200);
    [[actionSheet superview] addSubview:df];
    [[actionSheet superview] sendSubviewToBack:df];


    Hope it helps :)
    iOS application development lead at MobiLab Solutions.

    Expert in Java/Spring/OSGi, iOS app development.

    Enthusiastic C/C++, PHP, Cocoa Mac App developer.
  • ObezObez Posts: 1New Users
    edited January 2010
    funkytaco;112018 said:
    Thanks, I copy & pasted your code and it worked fine?!?!?

    Use my commented version and it will crash? I must be going cross-eyed. :confused:


    I don't see the problem....

    I'm gonna bump up your reputation, though. Thanks. Your solution works fine.
    I know you're probably finished with this but the only problem with your piece of code was the 'addSubview' you have used a capital 'V' when it should have been lowercase. I haven't been caught out by that one before but typos are generally a pain in my ***!

    Regards.
  • kiran kumarkiran kumar Posts: 5New Users
    edited February 2010
    AmanApps;112030 said:
    thats really tricky, not only putting any extra view on top, also to receive events.

    I had to put a table view above the buttons. Though I could use a xib to make a view like actions sheet and animate up.

    anyway, to put any image or view above the buttons and receive events, add that view to the actionsheet's superview. Like :


    df.frame = CGRectMake(0, 0, 320, 200);
    [[actionSheet superview] addSubview:df];
    [[actionSheet superview] sendSubviewToBack:df];


    Hope it helps :)


    This works fine for adding an image to an action sheet. but i want to add a label to the action sheet. How should i add the label. Can i have some sample code..

    Thanks in advance.
  • AmanAppsAmanApps Posts: 61Registered Users
    edited February 2010
    it should also work for labels. What error it gives?
    iOS application development lead at MobiLab Solutions.

    Expert in Java/Spring/OSGi, iOS app development.

    Enthusiastic C/C++, PHP, Cocoa Mac App developer.
  • kiran kumarkiran kumar Posts: 5New Users
    edited February 2010
    AmanApps;173993 said:
    it should also work for labels. What error it gives?

    It is not giving any errors but when we dismiss the action sheet the label is not dismissed with the action sheet. The label dismissed after action sheet got dismissed. that is my problem..

    Thanks for the reply.
  • AmanAppsAmanApps Posts: 61Registered Users
    edited February 2010
    oh, understood. we were adding the imageview to the background of the actionsheet bu this line:
    [[actionSheet superview] addSubview:df];


    try this line instead:
    [actionSheet  addSubview:yourlabel];


    Does this work now?
    iOS application development lead at MobiLab Solutions.

    Expert in Java/Spring/OSGi, iOS app development.

    Enthusiastic C/C++, PHP, Cocoa Mac App developer.
  • kiran kumarkiran kumar Posts: 5New Users
    edited February 2010
    AmanApps;174002 said:
    oh, understood. we were adding the imageview to the background of the actionsheet bu this line:
    [[actionSheet superview] addSubview:df];


    try this line instead:
    [actionSheet  addSubview:yourlabel];


    Does this work now?
    No its not working..if we addSubview directly to the actionsheet, now its not even displaying the label..
  • kiran kumarkiran kumar Posts: 5New Users
    edited February 2010
    AmanApps;174002 said:
    oh, understood. we were adding the imageview to the background of the actionsheet bu this line:
    [[actionSheet superview] addSubview:df];


    try this line instead:
    [actionSheet  addSubview:yourlabel];


    Does this work now?
    ok sorry aman its working..actually i gave frame of labels beyond action sheet that why it was not showing..Thanks for your help its working now..
  • kiran kumarkiran kumar Posts: 5New Users
    edited February 2010
    AmanApps;174002 said:
    oh, understood. we were adding the imageview to the background of the actionsheet bu this line:
    [[actionSheet superview] addSubview:df];


    try this line instead:
    [actionSheet  addSubview:yourlabel];


    Does this work now?
    I have another question, how can i change the font size of the action sheet title..
  • AmanAppsAmanApps Posts: 61Registered Users
    edited February 2010
    not sure if it is possible.
    iOS application development lead at MobiLab Solutions.

    Expert in Java/Spring/OSGi, iOS app development.

    Enthusiastic C/C++, PHP, Cocoa Mac App developer.
  • skajam66skajam66 Posts: 4New Users
    edited March 2010
    Here is some code that adds a green check mark image to an action sheet, centered and with same spacing as the default action sheet. The image is pure decoration - it does not respond to user touches. The code is specific to my application so you will need to adapt it as necessary.

    In some method that initiates the display of the action sheet (I'm triggering off of an NSNotification but it could be any method):

    - (void)notifyShowSuccessActionSheet:(NSNotification *) notification {

    NSLog(@\"In ETITMainViewController notifyShowSuccessActionSheet\n\");

    UIActionSheet *successActionSheet = [[[UIActionSheet alloc] initWithTitle:nil
    delegate:self
    cancelButtonTitle:nil
    destructiveButtonTitle:nil
    otherButtonTitles:@\"Do More\", @\"Done\", @\"Another Test?\", @\"Yet Another\", nil] autorelease];
    [successActionSheet setOpaque:NO];
    [successActionSheet setAlpha:0.8];
    [successActionSheet showFromToolbar:[[self naviController] toolbar]];

    }


    ...and in willPresentActionSheet:

    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet {

    UIImageView* successImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"CheckMark64.png\"]];
    NSInteger itemPadding;
    NSInteger topPadding = [[[actionSheet subviews] objectAtIndex:0] frame].origin.y;

    if ([[actionSheet subviews] count] > 1) {
    itemPadding = [[[actionSheet subviews] objectAtIndex:1] frame].origin.y
    - ([[[actionSheet subviews] objectAtIndex:0] frame].origin.y
    + [[[actionSheet subviews] objectAtIndex:0] frame].size.height);
    }
    else {
    itemPadding = [[[actionSheet subviews] objectAtIndex:0] frame].size.height / 4;
    }

    // resize action sheet frame to make space for image
    [actionSheet setFrame:CGRectMake([actionSheet frame].origin.x,
    [actionSheet frame].origin.y,
    [actionSheet frame].size.width,
    [actionSheet frame].size.height + [successImageView frame].size.height + itemPadding)];

    // re-position buttons
    for (UIControl *button in [actionSheet subviews]) {

    [button setFrame:CGRectMake([button frame].origin.x,
    [button frame].origin.y + [successImageView frame].size.height + itemPadding,
    [button frame].size.width,
    [button frame].size.height)];
    }

    [successImageView setFrame:CGRectMake(([[actionSheet superview] frame].size.width / 2) - [successImageView frame].size.width / 2,
    topPadding,
    [successImageView frame].size.width,
    [successImageView frame].size.height)];

    [actionSheet addSubview:successImageView];

    }
  • intomointomo Posts: 62Registered Users
    edited May 2010
    Thanks very much for that code. Very helpful.
    However, this isn't doing what I had hoped.
    I'm implementing the actionsheet

    UIActionSheet *alert = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@\"Yes\",@\"No\",nil];
    [alert showInView:self.view];
    [alert release];

    The delegate method adds the image and pushes the buttons lower. The buttons are so low, in fact, that you can't see them. Can you point me in the direction of changing the verticle position of the actionsheet so that I can see the image and all the buttons? Thanks again.
  • rafiqrafiq Posts: 27Registered Users
    edited July 2011
    Hi,
    Can I know where can I get the sample to integrate Instagram.Am trying it from last days.Even iphone hooks.
    Thanks
  • funkytacofunkytaco Posts: 412Registered Users
    edited July 2011
    rafiq;351160 said:
    Hi,
    Can I know where can I get the sample to integrate Instagram.Am trying it from last days.Even iphone hooks.
    Thanks
    Do not hijack threads. Start a new thread.
Sign In or Register to comment.