提醒窗口,单按钮,多按钮,播放声音,播放声音振动

来源:互联网 发布:淘宝千人千面害死卖家 编辑:程序博客网 时间:2024/05/17 01:22

//

//  ViewController.m

//  GettingAttention

//

//  Created by John Ray on 7/27/13.

//  Copyright (c) 2013 John E. Ray. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()

@property (weak, nonatomic)IBOutlet UILabel *userOutput;


- (IBAction)doAlert:(id)sender;

- (IBAction)doMultiButtonAlert:(id)sender;

- (IBAction)doAlertInput:(id)sender;

- (IBAction)doActionSheet:(id)sender;

- (IBAction)doSound:(id)sender;

- (IBAction)doAlertSound:(id)sender;

- (IBAction)doVibration:(id)sender;

@end


@implementation ViewController


- (void)viewDidLoad

{

    [superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}


- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (IBAction)doAlert:(id)sender {

    UIAlertView *alertDialog;

alertDialog = [[UIAlertView alloc]

                   initWithTitle:@"Alert Button Selected"

                   message:@"I need your attention NOW!"

                   delegate: nil

                   cancelButtonTitle: @"Ok"

                   otherButtonTitles: nil];

[alertDialog show];

}


- (IBAction)doMultiButtonAlert:(id)sender {

    UIAlertView *alertDialog;

    alertDialog = [[UIAlertView alloc]

                   initWithTitle:@"Alert Button Selected"

                   message:@"I need your attention NOW!"

                   delegate: self

                   cancelButtonTitle: @"Ok"

                   otherButtonTitles: @"Maybe Later", @"Never", nil];

[alertDialog show];

}


- (IBAction)doAlertInput:(id)sender {

    UIAlertView *alertDialog;

alertDialog = [[UIAlertView alloc]

                   initWithTitle: @"Email Address"

                   message:@"Please enter your email address:"

                   delegate: self

                   cancelButtonTitle: @"Ok"

                   otherButtonTitles: nil];

    alertDialog.alertViewStyle=UIAlertViewStylePlainTextInput;

[alertDialog show];

}


- (IBAction)doActionSheet:(id)sender {

    UIActionSheet *actionSheet;

actionSheet=[[UIActionSheetalloc] initWithTitle:@"Available Actions"

                                            delegate:self

                                   cancelButtonTitle:@"Cancel"

                              destructiveButtonTitle:@"Destroy"

                                   otherButtonTitles:@"Negotiate",@"Compromise",nil];

actionSheet.actionSheetStyle=UIActionSheetStyleDefault;

    [actionSheet showFromRect:[(UIButton *)senderframe]

                       inView:self.viewanimated:YES];

}



- (IBAction)doSound:(id)sender {

    SystemSoundID soundID;

    NSString *soundFile = [[NSBundlemainBundle]

 pathForResource:@"soundeffect"ofType:@"wav"];

    

    AudioServicesCreateSystemSoundID((__bridgeCFURLRef)

[NSURLfileURLWithPath:soundFile]

, &soundID);

    AudioServicesPlaySystemSound(soundID);

}



- (IBAction)doAlertSound:(id)sender {

    SystemSoundID soundID;

    NSString *soundFile = [[NSBundlemainBundle]

 pathForResource:@"alertsound"ofType:@"wav"];

    

    AudioServicesCreateSystemSoundID((__bridgeCFURLRef)

[NSURLfileURLWithPath:soundFile]

, &soundID);

    AudioServicesPlayAlertSound(soundID);

}


- (IBAction)doVibration:(id)sender {

    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

}


- (void)actionSheet:(UIActionSheet *)actionSheet

clickedButtonAtIndex:(NSInteger)buttonIndex {

NSString *buttonTitle=[actionSheetbuttonTitleAtIndex:buttonIndex];

if ([buttonTitle isEqualToString:@"Destroy"]) {

self.userOutput.text=@"Clicked 'Destroy'";

} else if ([buttonTitleisEqualToString:@"Negotiate"]) {

self.userOutput.text=@"Clicked 'Negotiate'";

} else if ([buttonTitleisEqualToString:@"Compromise"]) {

self.userOutput.text=@"Clicked 'Compromise'";

} else {

self.userOutput.text=@"Clicked 'Cancel'";

}

}


- (void)alertView:(UIAlertView *)alertView

clickedButtonAtIndex:(NSInteger)buttonIndex {

NSString *buttonTitle=[alertViewbuttonTitleAtIndex:buttonIndex];

if ([buttonTitle isEqualToString:@"Maybe Later"]) {

self.userOutput.text=@"Clicked 'Maybe Later'";

    } else if ([buttonTitleisEqualToString:@"Never"]) {

self.userOutput.text=@"Clicked 'Never'";

} else {

self.userOutput.text=@"Clicked 'Ok'";

}

    

    if ([alertView.title

         isEqualToString:@"Email Address"]) {

        self.userOutput.text=[[alertViewtextFieldAtIndex:0] text];

    }

}




@end

0 0
原创粉丝点击