• IOS 项目 小说 1


    架构:

              logo: logo标识(在image文件夹中修改某图片名称为icon)

              default: 默认页面的启动效果(在image文件夹中修改某图片名称为Default)

              image:存放图片(根目录下)

              4个UIViewController: CategoryViewController, PlayViewController, TimerViewController , AboutUsViewController

                       * CategoryViewController(目录)

                                          tableview data

                       * PlayViewController(播放)

                       * TimerViewController(定时)

                       * AboutUsViewController(关于)

              AppDelegate : start category module(程序开始启动目录view)

              5.audio

                       *import frameworks: audioltoolbox.frameword  & avfoundation.framework

     

     

     

     

    AppDelegate.h

    //
    //  AppDelegate.h
    //  novel_example
    //
    //  Created by chenzg on 3/23/11.
    //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    #import "CategoryViewController.h"
    #import "PlayViewController.h"
    #import "TimerViewController.h"
    #import "AboutUsViewController.h"
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    {
        
        UIWindow *window;
    
        //button declare 
        UIButton *btnCategory;
        UIButton *btnPlay;
        UIButton *btnTimer;
        UIButton *btnAboutUs;
        
        //nav
        UINavigationController *navCategory;
        UINavigationController *navPlay;
        UINavigationController *navTimer;
        UINavigationController *navAboutUs;
        
        //4 define uiviewcontroller
        CategoryViewController *categoryView;
        PlayViewController *playView;
        TimerViewController *timerView;
        AboutUsViewController *aboutUsView;
        
        UIView *viewToolBar;
        
        UIView *viewContent;
    
    }
    @property (strong, nonatomic) UIWindow *window;
    
    @end

    AppDelegate.m

      1 //
      2 //  AppDelegate.m
      3 //  novel_example
      4 //
      5 //  Created by chenzg on 3/23/11.
      6 //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
      7 //
      8 
      9 #import "AppDelegate.h"
     10 
     11 
     12 
     13 @implementation AppDelegate
     14 
     15 @synthesize window = _window;
     16 
     17 
     18 - (void)dealloc
     19 {
     20     [_window release];
     21       [super dealloc];
     22 }
     23 
     24 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
     25 {
     26     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
     27     // Override point for customization after application launch.
     28     //self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
     29     //self.window.rootViewController = self.viewController;
     30     
     31     viewContent = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
     32     viewContent .backgroundColor = [UIColor clearColor];
     33     [self.window addSubview:viewContent ];
     34     [viewContent  release];
     35     
     36     categoryView = [[CategoryViewController alloc]init];
     37     categoryView.view.frame = CGRectMake(0, 0, 320, 436);
     38     navCategory = [[UINavigationController alloc]initWithRootViewController:categoryView];
     39     [viewContent addSubview:navCategory.view];
     40     
     41     viewToolBar = [[UIView alloc]initWithFrame:CGRectMake(0, 410, 320, 47)];
     42     viewToolBar.backgroundColor = [UIColor clearColor];
     43     [_window addSubview:viewToolBar];
     44     [viewToolBar release];
     45     
     46     UIImageView *viewToolBarImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 47)];
     47     viewToolBarImg.image = [UIImage imageNamed:@"首页_按钮底图.png"];
     48     [viewToolBar addSubview:viewToolBarImg];
     49     [viewToolBarImg release];
     50     
     51     //category view
     52     
     53     btnCategory = [UIButton buttonWithType:UIButtonTypeCustom];
     54     btnCategory.frame = CGRectMake(30, 5, 51, 37);
     55     btnCategory.tag =1;
     56     [btnCategory setAdjustsImageWhenDisabled:YES];
     57     [btnCategory setBackgroundImage:[UIImage imageNamed:@"目录.png"] forState:UIControlStateNormal];
     58     [btnCategory addTarget:self action:@selector(categoryAction) forControlEvents:UIControlEventTouchDown];
     59     [viewToolBar addSubview:btnCategory];
     60     
     61     
     62     //play view
     63     
     64     btnPlay = [UIButton buttonWithType:UIButtonTypeCustom];
     65     btnPlay.frame = CGRectMake(94, 5, 51, 37);
     66     btnPlay.tag =2;
     67     [btnPlay setAdjustsImageWhenDisabled:YES];
     68     [btnPlay setBackgroundImage:[UIImage imageNamed:@"播放.png"] forState:UIControlStateNormal];
     69     [btnPlay addTarget:self action:@selector(playAction) forControlEvents:UIControlEventTouchDown];
     70     [viewToolBar addSubview:btnPlay];
     71     
     72     //timer
     73     
     74     btnTimer = [UIButton buttonWithType:UIButtonTypeCustom];
     75     btnTimer.frame = CGRectMake(161, 5, 51, 37);
     76     btnTimer.tag =3;
     77     [btnTimer setAdjustsImageWhenDisabled:YES];
     78     [btnTimer setBackgroundImage:[UIImage imageNamed:@"定时.png"] forState:UIControlStateNormal];
     79     [btnTimer addTarget:self action:@selector(timerAction) forControlEvents:UIControlEventTouchDown];
     80     [viewToolBar addSubview:btnTimer];
     81     
     82     //aboutus
     83     btnAboutUs = [UIButton buttonWithType:UIButtonTypeCustom];
     84     btnAboutUs.frame = CGRectMake(228, 5, 51, 37);
     85     btnAboutUs.tag =4;
     86     [btnAboutUs setAdjustsImageWhenDisabled:YES];
     87     [btnAboutUs setBackgroundImage:[UIImage imageNamed:@"关于.png"] forState:UIControlStateNormal];
     88     [btnAboutUs addTarget:self action:@selector(aboutusAction) forControlEvents:UIControlEventTouchDown];
     89     [viewToolBar addSubview:btnAboutUs];
     90     
     91     
     92     [self.window makeKeyAndVisible];
     93     return YES;
     94 }
     95 
     96 #pragma  mark ----------category action  method -----------------
     97 
     98 
     99 -(void)categoryAction{
    100 
    101     NSLog(@"categoryAction");
    102     [btnCategory setBackgroundImage:[UIImage imageNamed:@"目录.png"] forState:UIControlStateNormal];//选择的效果
    103     [btnPlay setBackgroundImage:[UIImage imageNamed:@"播放.png"] forState:UIControlStateNormal];//未选择的效果
    104     [btnTimer setBackgroundImage:[UIImage imageNamed:@"定时.png"] forState:UIControlStateNormal];//未选择的效果
    105     [btnAboutUs setBackgroundImage:[UIImage imageNamed:@"关于.png"] forState:UIControlStateNormal];//未选择的效果
    106 
    107     if ((navCategory.view.hidden =YES)) {
    108         //
    109         navCategory.view.hidden = NO;
    110         navPlay.view.hidden = YES;
    111         navTimer.view.hidden = YES;
    112         navAboutUs.view.hidden = YES;
    113     }
    114     
    115     
    116 
    117 }
    118 #pragma  mark ----------playAction  method -----------------
    119 
    120 -(void)playAction{
    121     NSLog(@"playAction");
    122     if (playView == nil) {
    123         //
    124         playView = [[PlayViewController alloc]init];
    125         playView.view.frame = CGRectMake(0, 0, 320, 436);
    126         navPlay = [[UINavigationController alloc]initWithRootViewController:playView];
    127         [viewContent addSubview:navPlay.view];
    128     }
    129     
    130     [btnCategory setBackgroundImage:[UIImage imageNamed:@"目录.png"] forState:UIControlStateNormal];//未选择的效果
    131     [btnPlay setBackgroundImage:[UIImage imageNamed:@"播放.png"] forState:UIControlStateNormal];//选择的效果
    132     [btnTimer setBackgroundImage:[UIImage imageNamed:@"定时.png"] forState:UIControlStateNormal];//未选择的效果
    133     [btnAboutUs setBackgroundImage:[UIImage imageNamed:@"关于.png"] forState:UIControlStateNormal];//未选择的效果
    134     
    135     if ((navPlay.view.hidden =YES)) {
    136         //
    137         navPlay.view.hidden = NO;
    138         navCategory.view.hidden = YES;
    139         navTimer.view.hidden = YES;
    140         navAboutUs.view.hidden = YES;
    141     }
    142     
    143 }
    144 
    145 
    146 #pragma  mark ----------timerAction  method -----------------
    147 
    148 
    149 
    150 -(void)timerAction{
    151 
    152     NSLog(@"timerAction");
    153     
    154     if (timerView == nil) {
    155         //
    156         timerView = [[TimerViewController alloc]init];
    157         timerView.view.frame = CGRectMake(0, 0, 320, 436);
    158         navTimer = [[UINavigationController alloc]initWithRootViewController:timerView];
    159         [viewContent addSubview:navTimer.view];
    160     }
    161     
    162     [btnCategory setBackgroundImage:[UIImage imageNamed:@"目录.png"] forState:UIControlStateNormal];//未选择的效果
    163     [btnPlay setBackgroundImage:[UIImage imageNamed:@"播放.png"] forState:UIControlStateNormal];//未选择的效果
    164     [btnTimer setBackgroundImage:[UIImage imageNamed:@"定时.png"] forState:UIControlStateNormal];//选择的效果
    165     [btnAboutUs setBackgroundImage:[UIImage imageNamed:@"关于.png"] forState:UIControlStateNormal];//未选择的效果
    166     
    167     if ((navTimer.view.hidden =YES)) {
    168         //
    169         navTimer.view.hidden = NO;
    170         navCategory.view.hidden = YES;
    171         navPlay.view.hidden = YES;
    172         navAboutUs.view.hidden = YES;
    173     }
    174 
    175 
    176 }
    177 
    178 #pragma  mark ----------aboutusAction  method -----------------
    179 
    180 
    181 
    182 -(void)aboutusAction{
    183 
    184     NSLog(@"aboutusAction");
    185     if (aboutUsView == nil) {
    186         //
    187         aboutUsView = [[AboutUsViewController alloc]init];
    188         aboutUsView.view.frame = CGRectMake(0, 0, 320, 436);
    189         navAboutUs = [[UINavigationController alloc]initWithRootViewController:aboutUsView];
    190         [viewContent addSubview:nav4.view];
    191     }
    192     
    193     [btnCategory setBackgroundImage:[UIImage imageNamed:@"目录.png"] forState:UIControlStateNormal];//未选择的效果
    194     [btnPlay setBackgroundImage:[UIImage imageNamed:@"播放.png"] forState:UIControlStateNormal];//未选择的效果
    195     [btnTimer setBackgroundImage:[UIImage imageNamed:@"定时.png"] forState:UIControlStateNormal];//未选择的效果
    196     [btnAboutUs setBackgroundImage:[UIImage imageNamed:@"关于.png"] forState:UIControlStateNormal];//选择的效果
    197     
    198     if ((navAboutUs.view.hidden =YES)) {
    199         //
    200         navAboutUs.view.hidden = NO;
    201         navCategory.view.hidden = YES;
    202         navPlay.view.hidden = YES;
    203         navTimer.view.hidden = YES;
    204     }
    205     
    206 
    207 
    208 }
    209 - (void)applicationWillResignActive:(UIApplication *)application
    210 {
    211     /*
    212      Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    213      Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    214      */
    215 }
    216 
    217 - (void)applicationDidEnterBackground:(UIApplication *)application
    218 {
    219     /*
    220      Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    221      If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    222      */
    223 }
    224 
    225 - (void)applicationWillEnterForeground:(UIApplication *)application
    226 {
    227     /*
    228      Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    229      */
    230 }
    231 
    232 - (void)applicationDidBecomeActive:(UIApplication *)application
    233 {
    234     /*
    235      Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    236      */
    237 }
    238 
    239 - (void)applicationWillTerminate:(UIApplication *)application
    240 {
    241     /*
    242      Called when the application is about to terminate.
    243      Save data if appropriate.
    244      See also applicationDidEnterBackground:.
    245      */
    246 }
    247 
    248 @end

     CategoryViewController.h

    //
    //  CategoryViewController.h
    //  novel_example
    //
    //  Created by chenzg on 3/23/11.
    //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface CategoryViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
    {
        UITableView *table;
        NSArray *arr;
    }
    
    
    @end

    CategoryViewController.m

    1 //
      2 //  CategoryViewController.m
      3 //  novel_example
      4 //
      5 //  Created by chenzg on 3/23/11.
      6 //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
      7 //
      8 
      9 #import "CategoryViewController.h"
     10 #import "CustomCell.h"
     11 #import "PlayViewController.h"
     12 
     13 @implementation CategoryViewController
     14 
     15 #pragma mark -------UITableViewDelegate method(行高):
     16 
     17 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
     18 
     19     return 45;
     20 
     21 }
     22 
     23 #pragma mark ---点击某行触发的方法
     24 
     25 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     26     
     27     PlayViewController *play = [[PlayViewController alloc]init];
     28     //
     29     play.arr_objindex = indexPath.row;
     30     
     31     [self.navigationController pushViewController:play animated:YES];
     32 }
     33 
     34 #pragma mark UITableViewDataSource method:
     35 
     36 
     37 
     38 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     39     static NSString *cellIdentifier = @"Cell";
     40 
     41     CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
     42     if (cell == nil) {
     43         cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
     44    
     45 
     46     [cell setTheImage:[UIImage imageNamed:@"条纹.png"]];
     47     
     48     //title
     49     UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 300, 40)];
     50     lbl.backgroundColor  = [UIColor clearColor];
     51     lbl.tag = indexPath.row;
     52     lbl.textColor = [UIColor blackColor];
     53     lbl.text = [arr objectAtIndex:indexPath.row];//arry indexPath.row
     54     [cell addSubview:lbl];
     55     
     56     
     57     }
     58     
     59     cell.selectionStyle = UITableViewCellSelectionStyleNone;
     60     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
     61     
     62     return cell;
     63 }
     64 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
     65 
     66     return 8;//[arr count];//array count
     67 }
     68 
     69 
     70 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;{
     71     return 1;
     72 
     73 }
     74 
     75 
     76 - (void)didReceiveMemoryWarning
     77 {
     78     // Releases the view if it doesn't have a superview.
     79     [super didReceiveMemoryWarning];
     80     
     81     // Release any cached data, images, etc that aren't in use.
     82 }
     83 
     84 #pragma mark - View lifecycle
     85 
     86 /*
     87 // Implement loadView to create a view hierarchy programmatically, without using a nib.
     88 - (void)loadView
     89 {
     90 }
     91 */
     92 
     93 -(void)viewWillAppear:(BOOL)animated{
     94     [super viewWillAppear:YES];
     95      self.navigationController.navigationBar.hidden = YES;
     96 
     97 }
     98 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
     99 - (void)viewDidLoad
    100 {
    101     [super viewDidLoad];
    102     self.navigationController.navigationBar.hidden = YES;
    103   
    104     UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 436)];
    105     imageView.image = [UIImage imageNamed:@"Default.png"];
    106     [self.view addSubview:imageView];
    107     [imageView release];
    108     
    109     arr = [[NSArray alloc]initWithObjects:@"秦朝帝王史话第一讲",@"秦朝帝王史话第二讲",@"秦朝帝王史话第三讲",@"秦朝帝王史话第四讲",@"秦朝帝王史话第五讲",@"秦朝帝王史话第六讲",@"秦朝帝王史话第七讲",@"秦朝帝王史话第八讲",@"秦朝帝王史话第九讲",@"秦朝帝王史话第十讲",@"秦朝帝王史话第十一讲",@"秦朝帝王史话第十二讲", nil];   
    110     
    111     
    112     table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 436) style:UITableViewStylePlain];
    113     table.scrollEnabled = YES;
    114     table.delegate = self;
    115     table.dataSource = self;
    116     table.backgroundColor = [UIColor clearColor];
    117    
    118     table.separatorStyle = UITableViewCellSeparatorStyleNone;// 去掉cell的线
    119     table.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    120     
    121     [self.view addSubview:table];
    122     
    123      
    124 }
    125 
    126 
    127 - (void)viewDidUnload
    128 {
    129     [super viewDidUnload];
    130     // Release any retained subviews of the main view.
    131     // e.g. self.myOutlet = nil;
    132 }
    133 
    134 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    135 {
    136     // Return YES for supported orientations
    137     return (interfaceOrientation == UIInterfaceOrientationPortrait);
    138 }
    139 
    140 @end

    PlayViewController.h

    1 //
     2 //  PlayViewController.h
     3 //  novel_example
     4 //
     5 //  Created by chenzg on 3/23/11.
     6 //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
     7 //
     8 
     9 #import <UIKit/UIKit.h>
    10 #import <AVFoundation/AVFoundation.h>
    11 #import <AudioToolbox/AudioToolbox.h>
    12 
    13 
    14 @interface PlayViewController : UIViewController<AVAudioPlayerDelegate>
    15 {
    16     AVAudioPlayer *player;
    17     UISlider *mySlider;
    18     UISlider *mySlider1;
    19     SystemSoundID soundID;
    20     
    21     NSInteger arr_objindex;
    22     NSString *str;
    23 
    24 }
    25 
    26 @property (nonatomic,retain)AVAudioPlayer *player;
    27 @property (nonatomic,retain)UISlider *mySlider;
    28 @property (nonatomic,retain)UISlider *mySlider1;
    29 @property (nonatomic) NSInteger arr_objindex;
    30 
    31 
    32 -(IBAction)sliderChange1:(id)sender;
    33 
    34 
    35 @end

    PlayViewController.m

    1 //
      2 //  PlayViewController.m
      3 //  novel_example
      4 //
      5 //  Created by chenzg on 3/23/11.
      6 //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
      7 //
      8 
      9 #import "PlayViewController.h"
     10 
     11 @implementation PlayViewController
     12 @synthesize player,mySlider,mySlider1,arr_objindex;
     13 
     14 -(void)viewWillAppear:(BOOL)animated{
     15 
     16     self.navigationController.navigationBar.hidden = YES;
     17 
     18 }
     19 
     20 -(IBAction)sliderChange1:(id)sender{
     21 
     22     NSLog(@"sliderChange");
     23     
     24     UISlider *slider = (UISlider *)sender;
     25     player.currentTime = slider.value * player.duration;
     26     NSLog(@"%f",player.currentTime);
     27     
     28     NSString *str1 = [NSString stringWithFormat:@"%f",player.currentTime];
     29     UILabel *sliderLbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 325, 20, 15)];
     30     sliderLbl.backgroundColor = [UIColor clearColor];
     31     sliderLbl.textColor = [UIColor redColor];
     32     sliderLbl.text = str1;
     33     sliderLbl.font = [UIFont systemFontOfSize:12];
     34     [self.view addSubview:sliderLbl];
     35     [sliderLbl release];
     36     
     37     
     38 
     39 }
     40 
     41 - (void)didReceiveMemoryWarning
     42 {
     43     // Releases the view if it doesn't have a superview.
     44     [super didReceiveMemoryWarning];
     45     
     46     // Release any cached data, images, etc that aren't in use.
     47 }
     48 
     49 #pragma mark - View lifecycle
     50 
     51 /*
     52 // Implement loadView to create a view hierarchy programmatically, without using a nib.
     53 - (void)loadView
     54 {
     55 }
     56 */
     57 
     58 
     59 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
     60 - (void)viewDidLoad
     61 {
     62     [super viewDidLoad];
     63     
     64     UIImageView *bottomImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 433)];
     65     bottomImg.image =[UIImage imageNamed:@"底图.png"];
     66     [self.view addSubview:bottomImg];
     67     [bottomImg release];
     68     
     69     UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(10, 290, 300, 96)];
     70     img.image =[UIImage imageNamed:@"首页_时间与进度轴.png"];
     71     [self.view addSubview:img];
     72     [img release];
     73     
     74     UILabel *leftLbl = [[UILabel alloc]initWithFrame:CGRectMake(20, 352, 20, 15)];
     75     leftLbl.backgroundColor =[UIColor clearColor];
     76     leftLbl.text =@"-";
     77     leftLbl.textColor = [UIColor yellowColor];
     78     [self.view addSubview:leftLbl];
     79     [leftLbl release];
     80     
     81     UILabel *rightLbl = [[UILabel alloc]initWithFrame:CGRectMake(290, 352, 20, 15)];
     82     rightLbl.backgroundColor =[UIColor clearColor];
     83     rightLbl.textColor =[UIColor yellowColor];
     84     rightLbl.text = @"+";
     85     [self.view addSubview:rightLbl];
     86     [rightLbl release];
     87     
     88     
     89     
     90     
     91     mySlider = [[UISlider alloc]initWithFrame:CGRectMake(40, 320, 240, 0)];
     92     mySlider.backgroundColor =[UIColor clearColor];
     93     mySlider.maximumValue = 50.0;
     94     mySlider.minimumValue = 10.0;
     95     mySlider.value = 10.0;
     96     [mySlider setMaximumTrackImage:[UIImage imageNamed:@"max.png"] forState:UIControlStateNormal];
     97     [mySlider setMinimumTrackImage:[UIImage imageNamed:@"min.png"] forState:UIControlStateNormal];
     98     [mySlider setThumbImage:[UIImage imageNamed:@"thumb.png"] forState:UIControlStateNormal];
     99     [mySlider addTarget:self action:@selector(sliderChange1:) forControlEvents:UIControlEventValueChanged];
    100     
    101     [self.view addSubview:mySlider];
    102     
    103     mySlider1 = [[UISlider alloc]initWithFrame:CGRectMake(40, 350, 240, 0)];
    104     mySlider1.backgroundColor = [UIColor clearColor];
    105     mySlider1.maximumValue = 50.0;
    106     mySlider1.minimumValue = 10.0;
    107     mySlider1.value = 22.0;
    108     [mySlider1 setMaximumTrackImage:[UIImage imageNamed:@"max.png"] forState:UIControlStateNormal];
    109     [mySlider1  setMinimumTrackImage:[UIImage imageNamed:@"min.png"] forState:UIControlStateNormal];
    110     [mySlider1 setThumbImage:[UIImage imageNamed:@"thumb.png"] forState:UIControlStateNormal];
    111     
    112     //UIControlEventValueChanged:值在变化
    113     
    114     [mySlider1 addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged];
    115     
    116     [self.view addSubview:mySlider1];
    117     
    118     switch (arr_objindex) {
    119         case 0:
    120             //
    121             str = @"001";
    122             break;
    123         case 1:
    124             str = @"002";
    125             break;
    126         case 2:
    127             str = @"003";
    128             break;
    129         case 3:
    130             str = @"004";
    131             break;
    132         case 4:
    133             str = @"005";
    134             break;
    135         case 5:
    136             str = @"006";
    137             break;
    138         
    139         case 6:
    140             str = @"007";
    141             break;
    142         case 7:
    143             str = @"008";
    144             break;
    145         case 8:
    146             str = @"009";
    147             break;
    148         case 9:
    149             str = @"010";
    150             break;
    151         case 10:
    152             str = @"011";
    153             break;
    154         case 11:
    155             str = @"012";
    156             break;   
    157             
    158         default:
    159             break;
    160     }
    161     
    162     
    163     
    164     if (player ==nil) {
    165         //
    166         
    167         NSError *error = nil;
    168         NSString *path = [[NSBundle mainBundle]pathForResource:str ofType:@"mp3"];
    169         NSURL *url = [NSURL fileURLWithPath:path];
    170         
    171         player  = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
    172         player.delegate = self;
    173         
    174     }
    175     
    176     [player prepareToPlay];
    177     [player play];
    178   
    179     [player setVolume:5.0];
    180     
    181     
    182 }
    183 #pragma mark -----------------control audio
    184 -(void)sliderChange:(id)sender{
    185 
    186     UISlider *slider = (UISlider *)sender;
    187     
    188     NSLog(@"%f",slider.value);
    189     [player setVolume:slider.value];
    190     
    191 
    192 }
    193 
    194 - (void)viewDidUnload
    195 {
    196     [super viewDidUnload];
    197     // Release any retained subviews of the main view.
    198     // e.g. self.myOutlet = nil;
    199 }
    200 
    201 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    202 {
    203     // Return YES for supported orientations
    204     return (interfaceOrientation == UIInterfaceOrientationPortrait);
    205 }
    206 
    207 @end

    TimerViewController.h

     1 //
     2 //  TimerViewController.h
     3 //  novel_example
     4 //
     5 //  Created by chenzg on 3/23/11.
     6 //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
     7 //
     8 
     9 #import <UIKit/UIKit.h>
    10 #import "PlayViewController.h"
    11 @interface TimerViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
    12 {
    13     UITableView *table;
    14     NSArray *arr;
    15     UILabel *timerLbl;
    16     UISwitch *switch_;
    17     PlayViewController *playView;
    18     
    19 }
    20 
    21 @property(nonatomic,retain)UISwitch *switch_;
    22 -(IBAction)switchChange:(id)sender;
    23 
    24 @end

    TimerViewController.m

    1 //
      2 //  TimerViewController.m
      3 //  novel_example
      4 //
      5 //  Created by chenzg on 3/23/11.
      6 //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
      7 //
      8 
      9 #import "TimerViewController.h"
     10 #import "CustomCell.h"
     11 @implementation TimerViewController
     12 
     13 @synthesize switch_;
     14 @synthesize player;
     15 -(IBAction)switchChange:(id)sender{
     16 
     17     NSLog(@"switch change");
     18     UISwitch *mySwitch = (UISwitch *)sender;
     19     BOOL setting = mySwitch.isOn;//open
     20     [switch_ setOn:setting animated:YES];
     21     
     22 
     23 }
     24 
     25 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
     26 {
     27     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
     28     if (self) {
     29         // Custom initialization
     30     }
     31     return self;
     32 }
     33 
     34 - (void)didReceiveMemoryWarning
     35 {
     36     // Releases the view if it doesn't have a superview.
     37     [super didReceiveMemoryWarning];
     38     
     39     // Release any cached data, images, etc that aren't in use.
     40 }
     41 
     42 #pragma mark - View lifecycle
     43 
     44 /*
     45 // Implement loadView to create a view hierarchy programmatically, without using a nib.
     46 - (void)loadView
     47 {
     48 }
     49 */
     50 #pragma mark -------UITableViewDelegate method(行高):
     51 
     52 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
     53     
     54     return 45;
     55     
     56 }
     57 
     58 #pragma mark ---点击某行触发的方法
     59 
     60 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     61     NSLog(@"didselect");
     62     switch (indexPath.row) {
     63         case 10:
     64             //
     65              playView.player.currentTime = 10;
     66             if (playView.player.duration==600) {
     67                 //
     68                 [playView.player stop];
     69             }
     70             break;
     71             
     72         default:
     73             break;
     74     }
     75    
     76     
     77     
     78 }
     79 
     80 #pragma mark UITableViewDataSource method:
     81 
     82 
     83 
     84 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     85     static NSString *cellIdentifier = @"Cell";
     86     
     87     CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
     88     if (cell == nil) {
     89         cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
     90         
     91         
     92         [cell setTheImage:[UIImage imageNamed:@"条纹.png"]];
     93         
     94         
     95         
     96         if (indexPath.row ==0) {
     97             //
     98           
     99         }else{
    100                
    101         
    102         //title
    103         UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 300, 40)];
    104         lbl.backgroundColor  = [UIColor clearColor];
    105         lbl.tag = indexPath.row;
    106         lbl.textColor = [UIColor blackColor];
    107         lbl.text = [arr objectAtIndex:indexPath.row];//arry indexPath.row
    108         [cell addSubview:lbl];
    109             
    110         }
    111               
    112         
    113 
    114         
    115         
    116     }
    117     
    118     cell.selectionStyle = UITableViewCellSelectionStyleNone;
    119     //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    120     
    121     return cell;
    122 }
    123 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    124     
    125     return 7;//[arr count];//array count
    126 }
    127 
    128 
    129 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;{
    130     return 1;
    131     
    132 }
    133 -(void)viewWillAppear:(BOOL)animated{
    134     [super viewWillAppear:YES];
    135     self.navigationController.navigationBar.hidden = YES;
    136     
    137 }
    138 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    139 - (void)viewDidLoad
    140 {
    141     [super viewDidLoad];
    142       
    143     UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 436)];
    144     imageView.image = [UIImage imageNamed:@"Default.png"];
    145     [self.view addSubview:imageView];
    146     [imageView release];
    147     
    148     arr = [[NSArray alloc]initWithObjects:@"",@"10分钟",@"20分钟",@"30分钟",@"40分钟",@"50分钟",@"60分钟",nil];   
    149     
    150     
    151     table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 436) style:UITableViewStylePlain];
    152     table.scrollEnabled = YES;
    153     table.delegate = self;
    154     table.dataSource = self;
    155     table.backgroundColor = [UIColor clearColor];
    156     
    157     table.separatorStyle = UITableViewCellSeparatorStyleNone;// 去掉cell的线
    158     table.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    159  
    160     [self.view addSubview:table];
    161     
    162     switch_ = [[UISwitch alloc]initWithFrame:CGRectMake(100, 10, 100, 30)];
    163     switch_.backgroundColor =[UIColor clearColor];
    164     [switch_ addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged];
    165   
    166     [self.view addSubview:switch_]; 
    173 }
    174 
    179 - (void)viewDidUnload
    180 {
    181     [super viewDidUnload];
    182     // Release any retained subviews of the main view.
    183     // e.g. self.myOutlet = nil;
    184 }
    185 
    186 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    187 {
    188     // Return YES for supported orientations
    189     return (interfaceOrientation == UIInterfaceOrientationPortrait);
    190 }
    191 
    192 @end

    AboutUsViewController.h

    1 //
     2 //  AboutUsViewController.h
     3 //  novel_example
     4 //
     5 //  Created by chenzg on 3/23/11.
     6 //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
     7 //
     8 
     9 #import <UIKit/UIKit.h>
    10 
    11 @interface AboutUsViewController : UIViewController
    12 
    13 @end

    AboutUsViewController.m

     1 //
     2 //  AboutUsViewController.m
     3 //  novel_example
     4 //
     5 //  Created by chenzg on 3/23/11.
     6 //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
     7 //
     8 
     9 #import "AboutUsViewController.h"
    10 
    11 @implementation AboutUsViewController
    12 
    13 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    14 {
    15     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    16     if (self) {
    17         // Custom initialization
    18     }
    19     return self;
    20 }
    21 
    22 - (void)didReceiveMemoryWarning
    23 {
    24     // Releases the view if it doesn't have a superview.
    25     [super didReceiveMemoryWarning];
    26     
    27     // Release any cached data, images, etc that aren't in use.
    28 }
    29 
    30 #pragma mark - View lifecycle
    31 
    32 /*
    33 // Implement loadView to create a view hierarchy programmatically, without using a nib.
    34 - (void)loadView
    35 {
    36 }
    37 */
    38 
    39 /*
    40 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    41 - (void)viewDidLoad
    42 {
    43     [super viewDidLoad];
    44 }
    45 */
    46 
    47 - (void)viewDidUnload
    48 {
    49     [super viewDidUnload];
    50     // Release any retained subviews of the main view.
    51     // e.g. self.myOutlet = nil;
    52 }
    53 
    54 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    55 {
    56     // Return YES for supported orientations
    57     return (interfaceOrientation == UIInterfaceOrientationPortrait);
    58 }
    59 
    60 @end
    
    CustomCell.h
    
    
     1 //
     2 //  CustomCell.h
     3 //  novel_example
     4 //
     5 //  Created by chenzg on 4/7/11.
     6 //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
     7 //
     8 
     9 #import <UIKit/UIKit.h>
    10 
    11 @interface CustomCell : UITableViewCell
    12 {
    13     UIImageView *imageView;
    14 
    15 }
    16 
    17 -(void)setTheImage:(UIImage *)icon;
    18 
    19 
    20 @end

    CustomCell.m

    1 //
     2 //  CustomCell.m
     3 //  novel_example
     4 //
     5 //  Created by chenzg on 4/7/11.
     6 //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
     7 //
     8 
     9 #import "CustomCell.h"
    10 
    11 @implementation CustomCell
    12 
    13 
    14 #pragma mark---------setTheImage------
    15 
    16 -(void)setTheImage:(UIImage *)icon{
    17 
    18     imageView = [[UIImageView alloc]initWithImage:icon];
    19     imageView.frame = CGRectMake(0, 0, 320, 45);
    20     [self.contentView addSubview:imageView];
    21     
    22 
    23 }
    24 
    25 #pragma  mark ------去除cell的背景色
    26 
    27 -(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    28     
    29     
    30     if (self== [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
    31         //cell background kill
    32         
    33         [self.contentView setBackgroundColor:[UIColor clearColor]];
    34         
    35     }
    36 
    37     
    38     return self;
    39 
    40 }
    41 
    42 -(void)setSelected:(BOOL)selected animated:(BOOL)animated{
    43 
    44     [super setSelected:selected animated:animated];
    45     
    46     if (selected == YES) {
    47         //
    48         imageView.alpha =1;//cell被图片覆盖
    49                 
    50     }else{
    51     
    52         imageView.alpha =.2;//cell透明
    53     }
    54 
    55 }
    56 
    57 - (void)didReceiveMemoryWarning
    58 {
    59     // Releases the view if it doesn't have a superview.
    60     [super didReceiveMemoryWarning];
    61     
    62     // Release any cached data, images, etc that aren't in use.
    63 }
    64 
    65 #pragma mark - View lifecycle
    66 
    67 /*
    68 // Implement loadView to create a view hierarchy programmatically, without using a nib.
    69 - (void)loadView
    70 {
    71 }
    72 */
    73 
    74 /*
    75 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    76 - (void)viewDidLoad
    77 {
    78     [super viewDidLoad];
    79 }
    80 */
    81 
    82 - (void)viewDidUnload
    83 {
    84     [super viewDidUnload];
    85     // Release any retained subviews of the main view.
    86     // e.g. self.myOutlet = nil;
    87 }
    88 
    89 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    90 {
    91     // Return YES for supported orientations
    92     return (interfaceOrientation == UIInterfaceOrientationPortrait);
    93 }
    94 
    95 @end
  • 相关阅读:
    【转】Xilinx 7系列FPGA 高速收发器GTX/GTH的一些基本概念
    jsoncpp中文乱码问题
    Excel VBA ——如何快速填充纸质登记表
    Excel VBA——如何快速将一个excel文件中的各个工作表分别保存成不同的工作簿
    等保测评整改过程遇到的问题及解决方案
    清除阿里云服务器挖矿程序过程
    python机器学习——随机森林算法
    python机器学习——kmeans聚类算法
    python机器学习——BP(反向传播)神经网络算法
    python机器学习——SVM支持向量机
  • 原文地址:https://www.cnblogs.com/CharlesGrant/p/3639490.html
Copyright © 2020-2023  润新知