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

//

//  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

{

    [super viewDidLoad];

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

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // 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=[[UIActionSheet alloc] initWithTitle:@"Available Actions"

                                            delegate:self

                                   cancelButtonTitle:@"Cancel"

                              destructiveButtonTitle:@"Destroy"

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

actionSheet.actionSheetStyle=UIActionSheetStyleDefault;

    [actionSheet showFromRect:[(UIButton *)sender frame]

                       inView:self.view animated:YES];

}



- (IBAction)doSound:(id)sender {

    SystemSoundID soundID;

    NSString *soundFile = [[NSBundle mainBundle]

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

    

    AudioServicesCreateSystemSoundID((__bridge CFURLRef)

[NSURL fileURLWithPath:soundFile]

, &soundID);

    AudioServicesPlaySystemSound(soundID);

}



- (IBAction)doAlertSound:(id)sender {

    SystemSoundID soundID;

    NSString *soundFile = [[NSBundle mainBundle]

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

    

    AudioServicesCreateSystemSoundID((__bridge CFURLRef)

[NSURL fileURLWithPath:soundFile]

, &soundID);

    AudioServicesPlayAlertSound(soundID);

}


- (IBAction)doVibration:(id)sender {

    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

}


- (void)actionSheet:(UIActionSheet *)actionSheet

clickedButtonAtIndex:(NSInteger)buttonIndex {

NSString *buttonTitle=[actionSheet buttonTitleAtIndex:buttonIndex];

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

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

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

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

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

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

} else {

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

}

}


- (void)alertView:(UIAlertView *)alertView

clickedButtonAtIndex:(NSInteger)buttonIndex {

NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];

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

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

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

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

} else {

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

}

    

    if ([alertView.title

         isEqualToString: @"Email Address"]) {

        self.userOutput.text=[[alertView textFieldAtIndex:0] text];

    }

}




@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值