添加背景和背景音乐

来源:互联网 发布:淘宝网黄金生命胶囊 编辑:程序博客网 时间:2024/04/29 14:13

    在appdelegate中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions函数中添加如下代码,实现桌面背景和背景音乐

    UIView *beview=[[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 460)];

   //创建UIImage对象

    UIImage *im=[UIImage imageNamed:@"456.jpg"];

    beview.backgroundColor=[UIColorcolorWithPatternImage:im];

    

//    beview.backgroundColor=[UIColor brownColor];

//    UIImage *im=[UIImage imageNamed:@"bar.png"];

    [self.windowaddSubview:beview];

    [beview release];

    

    

    

   //播放声音

    

   NSString *mp3Path=[[NSBundlemainBundle] pathForResource:@"Only One"ofType:@"mp3"];

   //url分两种  一种是文件urlfile 一种是网络urlhttp://

    NSURL *url=[NSURL fileURLWithPath:mp3Path];

   AVAudioPlayer *player=[[AVAudioPlayeralloc] initWithContentsOfURL:urlerror:nil];

    

   //设置循环次数

    player.numberOfLoops=2;

    

//    告诉系统要播放音频

    [player prepareToPlay];

    [player play];

    

    [self.windowmakeKeyAndVisible];

   return YES;

}


原创粉丝点击