Ios 按下图像按钮时添加声音
我有这个按钮在滚动视图,我需要播放一个声音时,按下它Ios 按下图像按钮时添加声音,ios,xcode,image,audio,button,Ios,Xcode,Image,Audio,Button,我有这个按钮在滚动视图,我需要播放一个声音时,按下它 UIButton *profileButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [profileButton setImage:[UIImage imageNamed:@"test.jpg"] forState:UIControlStateNormal]; [profileButton setImage:[UIImage imageNamed:@"tes
UIButton *profileButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[profileButton setImage:[UIImage imageNamed:@"test.jpg"] forState:UIControlStateNormal];
[profileButton setImage:[UIImage imageNamed:@"test.jpg"] forState:UIControlStateHighlighted];
profileButton.frame = CGRectMake(0, 620, 320, 250);
[self.scrollView addSubview:profileButton];
我怎么能这样做?
谢谢,添加触按按钮
[profileButton addTarget:self action:@selector(onButtonPress) forControlEvents:UIControlEventTouchUpInside];
//需要这个包含文件和AudioToolbox框架吗
#import <AudioToolbox/AudioToolbox.h>
-(void) onButtonPress {
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"mp3"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
}