sheet = [[UIActionSheet alloc] initWithTitle:@"Shared To" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Facebook" otherButtonTitles:@"Twitter", @"Google Plus", @"Youtube", nil]; [[[sheet valueForKey:@"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:@"facebook.png"] forState:UIControlStateNormal]; [[[sheet valueForKey:@"_buttons"] objectAtIndex:1] setImage:[UIImage imageNamed:@"twitter.png"] forState:UIControlStateNormal]; [[[sheet valueForKey:@"_buttons"] objectAtIndex:2] setImage:[UIImage imageNamed:@"google-plus.png"] forState:UIControlStateNormal]; [[[sheet valueForKey:@"_buttons"] objectAtIndex:3] setImage:[UIImage imageNamed:@"youtube.png"] forState:UIControlStateNormal]; // Show the sheet [sheet showInView:self.view]; [sheet release];
// // ViewController.h // ActionSheetImages // // Created by Weerachai on 12/5/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIActionSheetDelegate> { IBOutlet UILabel *lblResult; } - (IBAction)btnOpenSheet:(id)sender; @end
// // ViewController.m // ActionSheetImages // // Created by Weerachai on 12/5/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController { UIActionSheet *sheet; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (IBAction)btnOpenSheet:(id)sender { sheet = [[UIActionSheet alloc] initWithTitle:@"Shared To" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Facebook" otherButtonTitles:@"Twitter", @"Google Plus", @"Youtube", nil]; [[[sheet valueForKey:@"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:@"facebook.png"] forState:UIControlStateNormal]; [[[sheet valueForKey:@"_buttons"] objectAtIndex:1] setImage:[UIImage imageNamed:@"twitter.png"] forState:UIControlStateNormal]; [[[sheet valueForKey:@"_buttons"] objectAtIndex:2] setImage:[UIImage imageNamed:@"google-plus.png"] forState:UIControlStateNormal]; [[[sheet valueForKey:@"_buttons"] objectAtIndex:3] setImage:[UIImage imageNamed:@"youtube.png"] forState:UIControlStateNormal]; // Show the sheet [sheet showInView:self.view]; [sheet release]; } - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { switch (buttonIndex) { case 0: lblResult.text = @" Your Selected Item 0"; break; case 1: lblResult.text = @" Your Selected Item 1"; break; case 2: lblResult.text = @" Your Selected Item 2"; break; case 3: lblResult.text = @" Your Selected Item 3"; break; case 4: lblResult.text = @" Your Selected Item 4"; break; default: break; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [lblResult release]; [super dealloc]; } @end
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Shared!" message:@"Share to ?" delegate: self cancelButtonTitle:@"Facebook" otherButtonTitles:@"Twitter", nil]; [[[alert valueForKey:@"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:@"facebook.png"] forState:UIControlStateNormal]; [[[alert valueForKey:@"_buttons"] objectAtIndex:1] setImage:[UIImage imageNamed:@"twitter.png"] forState:UIControlStateNormal]; [alert show]; [alert release];
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท