开发者

add sounds, buttons and image on the function of button programmatically

i want to know i add sound & image or label on the function of button which is created prgrammatic开发者_如何学Cally on the click of button. firstly my sound was working fy9, but after adding image and label on that same function , sound is not working.

help ME!

Anks.....


try this, worked for me:

in the .h file of the view controller ur using add the "-(IBAction) playSound:(id)sender;" before "@end"

in the .m file of the view controller add the following code:

-(IBAction) playSound:(id)sender{

NSString *path = [[NSBundle mainBundle] pathForResource:@"awh_man" ofType:@"wav"];
AVAudioPlayer* sound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

sound.delegate=self;
[sound play];

} 

NOTE that you need to add the AVFoundation framework to your project. Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜