随笔学习二

本文介绍了一个iOS应用的界面设计与音视频播放控制实现。应用使用UITableView展示动态加载的内容,每个单元格显示从PropertyList.plist读取的数据,包括图片和文本标签。此外,文章还展示了如何在第二个控制器中集成AVAudioPlayer来播放本地MP3文件,并通过按钮控制播放与暂停。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

one

#define WC [UIScreen mainScreen].bounds.size.width
#import “oneViewController.h”
#import “threeViewController.h”
#import “Model.h”
@interface oneViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)NSMutableArray *dataSource;
@property(nonatomic,strong)NSMutableArray *imageSource;

@property(nonatomic,strong)UITableView *tbv;

@end

@implementation oneViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.dataSource=[NSMutableArray new];

    self.imageSource = [NSMutableArray new];
    self.view.backgroundColor = [UIColor redColor];
    _tbv=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tbv.delegate=self;
    _tbv.dataSource=self;
    [self heardView];
    [self diaoyong];
    [self.view addSubview:_tbv];
    }
    -(void)diaoyong{
    NSURL *url=[[NSBundle mainBundle]URLForResource:@“Property List.plist” withExtension:nil];
    NSDictionary *dic=[NSDictionary dictionaryWithContentsOfURL:url];
    for (NSDictionary *dict in dic[@“tab”]) {
    Model *model=[[Model alloc]init];
    [model setValuesForKeysWithDictionary:dict];
    [self.dataSource addObject:model];
    }
    for (NSDictionary *dicc in dic[@“tab”]) {
    [self.imageSource addObject:dicc];
    }
    NSLog(@“=====%@”,self.dataSource);
    }
    -(void)heardView
    {
    //网格状头视图
    UIView *heard=[[UIView alloc]initWithFrame:CGRectMake(0, 0,WC, 280)];
    heard.backgroundColor=[UIColor grayColor];
    UIButton *btnI=[[UIButton alloc]initWithFrame:CGRectMake(10, 30, WC/4-5, 100)];
    [btnI setImage:[UIImage imageNamed:@“Image”] forState:UIControlStateNormal];
    [heard addSubview:btnI];
    UIButton *btnII=[[UIButton alloc]initWithFrame:CGRectMake(WC/4+10,30, WC/4-5, 100)];
    [btnII setImage:[UIImage imageNamed:@“Image-1”] forState:UIControlStateNormal];
    [heard addSubview:btnII];
    UIButton *btnIIi=[[UIButton alloc]initWithFrame:CGRectMake(WC/2+10,30, WC/2-10, 100)];
    [btnIIi setImage:[UIImage imageNamed:@“Image-2”] forState:UIControlStateNormal];
    [heard addSubview:btnIIi];

    for (int i=0; i<4; i++) {
    NSArray *arr=@[@“Image-3”,@“Image-4”,@“Image-3”,@“Image-4”];
    UIButton btnV=[[UIButton alloc]initWithFrame:CGRectMake(5+WC/4i+5,140, WC/4-5, 110)];
    [btnV setImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];
    [heard addSubview:btnV];
    }

    self.tbv.tableHeaderView=heard;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

return  self.dataSource.count;

}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
    cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
}
Model *model=[[Model alloc]init];
model=self.dataSource[indexPath.row];
//设置cell内容
cell.textLabel.text = [NSString stringWithFormat:@"%@",model.zlable];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",model.flable];
cell.imageView.image = [UIImage imageNamed:model.image];
cell.accessoryType=1;


return cell;

}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

//跳转到第二个控制器
threeViewController *secVc = [threeViewController new];

[self.navigationController pushViewController:secVc animated:YES];

}
@end

three

#define WC [UIScreen mainScreen].bounds.size.width
#define HC [UIScreen mainScreen].bounds.size.height
#import “SDAutoLayout.h”//自适应头文件
#import <AVFoundation/AVFoundation.h>//歌曲播放器
#import “threeViewController.h”

@interface threeViewController ()
@property(nonatomic,strong)AVAudioPlayer *player;
@property(nonatomic,strong)UIButton *btn;
@property(nonatomic,assign)int x;
@end

@implementation threeViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIGraphicsBeginImageContext(self.view.frame.size);
    [[UIImage imageNamed:@“1-1.png”] drawInRect:self.view.bounds];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.view.backgroundColor=[UIColor colorWithPatternImage:image];
    NSString *file=[[NSBundle mainBundle]pathForResource:@“高山槐花开” ofType:@“mp3”];
    NSLog(@“asdasdasd%@”,file);
    NSURL *URL =[NSURL fileURLWithPath:file];

    self.player=[[AVAudioPlayer alloc]initWithContentsOfURL:URL error:nil];

    self.x=1;
    [self.player play];
    [self btnview];

}
-(void)btnview
{
UIView *btnview=[[UIView alloc]init];

btnview.backgroundColor=[UIColor lightGrayColor];


_btn=[[UIButton alloc]initWithFrame:CGRectMake(10, 20, 180, 60)];

[_btn setImage:[[UIImage imageNamed:@"btn_play"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];


[_btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[btnview addSubview:_btn];
[self.view addSubview:btnview];
btnview.sd_layout
.leftSpaceToView(self.view, 0)
.bottomSpaceToView(self.view, 80)
.heightIs(100)
.widthIs(WC);

}
-(void)click{

if (self.x ==0){
      [_btn setImage:[[UIImage imageNamed:@"btn_play"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.player pause];
self.x=1;
}else if (self.x ==1) {
[_btn setImage:[[UIImage imageNamed:@"btn_pause"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[self.player play];
self.x =0;

}

}

@end

Model

@property(nonatomic,strong)NSString *image,*zlable,*flable;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值