【发布时间】:2013-04-13 00:46:29
【问题描述】:
我在 4 个按钮中有 4 个图像:imag01.jpg、imag02.jpg、imag03.jpg、imag04.jpg 和 4 个声音:sound01.aifc、sound02.aifc、sound03.aifc、sound04.aifc。
我正在生成 4 个这样的按钮:
UIButton *oneButton = [UIButton buttonWithType:UIButtonTypeCustom];
[oneButton setTitle:@"1" forState:UIControlStateNormal];
[oneButton setTitle:@"1" forState:UIControlStateHighlighted];
[oneButton setImage:[UIImage imageNamed:@"imag01.jpg"] forState:UIControlStateNormal];
[oneButton setImage:[UIImage imageNamed:@"imag01.jpg"] forState:UIControlStateHighlighted];
oneButton.frame = CGRectMake(20, 100, 140, 100);
[scrMain addSubview:oneButton];
我想生成一个从 1 到 4 的随机数(例如 3),播放与之相关的声音 (sound03.aifc) 并要求用户为该声音按下正确的按钮 (imag03.jpg)。
如何在按钮和声音之间建立联系?
【问题讨论】:
-
与其要求指向示例代码的指针(“资源请求”问题),不如在 SO 上解释您的问题并寻求解决方案的帮助。这样,当其他人遇到类似问题时,这里的答案也可以帮助他们。我已经稍微编辑了您的问题以反映这一点 - 如果您认为需要,请查看并修改。
标签: ios objective-c uiimageview uibutton arc4random