设为首页 加入收藏

TOP

【代码笔记】iOS-看图听故事(一)
2017-10-13 10:17:16 】 浏览:3993
Tags:代码 笔记 iOS- 故事

一,效果图。

二,工程图。

三,代码。

RootViewController.h

复制代码
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface RootViewController : UIViewController
<AVAudioPlayerDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
    UIImageView * backImageView;
    AVAudioPlayer *_audioPlayer;
    NSMutableArray *musicArray;
    NSMutableArray *titleArray;
    
    int songIndex;
    UIButton * leftButton;
    UIButton * rightButton;
    
    UILabel *titleLabel;
    UISlider *Slider;
    UISlider *volumeSlider;
    NSTimer * processTimer;
    NSTimer * timer1;
    
}
@end
复制代码

 

RootViewController.m

复制代码
#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = @"故事";

    //初始化数据
    [self initData];
    //初始化背景图
    [self initBackgroundView];
    
}
#pragma -mark -functions
//初始化数据
-(void)initData
{
    musicArray=[[NSMutableArray alloc]initWithObjects:@"7",@"11",@"9",@"17",@"5",@"6",@"1",@"8",@"15",@"10",@"2",@"12",@"13",@"14",@"4",@"16",@"3",@"18", nil];
    titleArray=[[NSMutableArray alloc]initWithObjects:@"三头公牛和狮子",@"小红帽",@"天女散花",@"朋友再见",@"女娲造人",@"天神的哑水",@"小青蛙听故事",@"淘淘的愿望",@"讲礼貌",@"丑小鸭",@"老鼠,小鸟和香肠",@"两头驴子",@"驴子和主人",@"四个朋友",@"奖品",@"没法通过",@"五颗豌豆",@"彼得*潘", nil];
    
}
//初始化背景图
-(void)initBackgroundView
{
    
    self.navigationController.navigationBar.tintColor =[UIColor orangeColor];
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:69.0/255 green:161.0/255 blue:241.0/255 alpha:1];
    
    
    //背景
    backImageView= [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 320, 460)];
    backImageView.image= [UIImage imageNamed:[NSString stringWithFormat:@"%@.jpg",[musicArray objectAtIndex:songIndex]]];
    [self.view addSubview:backImageView];
    
    
    //播放
    UIButton* button= [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(130, 260, 60, 50);
    button.tag=100;
    [button addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
    [self.view addSubview:button];
    
    //上一首
    leftButton= [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame=CGRectMake(50, 260, 60, 50);
    [leftButton addTarget:self action:@selector(prier) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"left.png"] forState:UIControlStateNormal];
    [self.view addSubview:leftButton];
    
    //下一首
    rightButton= [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame=CGRectMake(210, 260, 60, 50);
    [rightButton addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUp
首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇xCode5 在ios7模拟器中出现__cxa_.. 下一篇多线程编程1 - NSThread

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目