qq音乐播放界面按钮


@property(strong,nonatomic)UIScrollView *scrollView;//滚动视图
@property(strong,nonatomic)UIPageControl *pageCtrl;//页控器
@property(strong,nonatomic)UIView *playControlView;//下部控制播放的视图(不跟着滚动)
@property(strong,nonatomic)UISlider *slider;//控制音乐播放
@property(strong,nonatomic)UIButton *mvBtn;//播放MV
@property(strong,nonatomic)UILabel *nameLabel;//显示歌手姓名
@property(strong,nonatomic)UILabel *songLabel;//显示歌曲和专辑
@property(strong,nonatomic)UIButton *downBtn;//下载按钮
@property(strong,nonatomic)UIButton *likeBtn;//喜欢按钮
@property(strong,nonatomic)UIButton *playBtn;//播放按钮
@property(strong,nonatomic)UIButton *randomBtn;//随机播放按钮
@property(strong,nonatomic)UIButton *backBtn;//上一首按钮
@property(strong,nonatomic)UIButton *nextBtn;//下一首按钮
@property(strong,nonatomic)UIButton *shareBtn;//分享按钮

// 当前播放时间的显示标签
@property(nonatomic,strong)UILabel *curtimeLabel;
// 歌曲持续时间的标签
@property(nonatomic,strong)UILabel *durationLabel;

- (UIButton *)mvBtn{
    if (_mvBtn == nil) {
        _mvBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _mvBtn.frame = CGRectMake(280, 10, 35, 15);
        [_mvBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    }
    return _mvBtn;
}
- (UIPageControl *)pageCtrl{
    if (_pageCtrl == nil) {
        _pageCtrl = [[UIPageControl alloc] init];
        _pageCtrl.numberOfPages = 3;
        _pageCtrl.frame = CGRectMake(140, 40, 40, 20);
        [_pageCtrl addTarget:self action:@selector(pageCtlDidHandle:) forControlEvents:UIControlEventValueChanged];
    }
    return _pageCtrl;
}
- (UISlider *)slider{
    if (_slider == nil) {
        _slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 60, 320, 2)];
        _slider.tintColor = [UIColor whiteColor];
        [_slider setThumbImage:[UIImage imageNamed:@"thumb.png"] forState:UIControlStateNormal];
    }
    return _slider;
}


- (UIScrollView *)scrollView{
    if (_scrollView == nil) {
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, self.frame.size.height - 154)];
        _scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width * 3, 0);
        _scrollView.bounces= YES;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.pagingEnabled = YES;
        for (int i = 0; i < 3; i ++) {
            CGRect frame = _scrollView.frame;
            
            if (i == 1) {
                UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width * i, 0, frame.size.width, frame.size.height)];
                img.image = [UIImage imageNamed:@"IMG_0025.jpg"];
                img.backgroundColor = [UIColor grayColor];
                [_scrollView addSubview:img];
            }
            else
            {
                UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(frame.size.width * i, 0, frame.size.width, frame.size.height) style:UITableViewStylePlain];
                tableView.tag = 4000 + i;
                [_scrollView addSubview:tableView];
            }
            
            _scrollView.delegate = self;
        }
    }
    return _scrollView;
}
- (UILabel *)nameLabel{
    if (_nameLabel == nil) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 8, 100, 20)];
        _nameLabel.text = @"姓名";
        _nameLabel.font = [UIFont boldSystemFontOfSize:18];
        _nameLabel.textColor = [UIColor whiteColor];
    }
    return  _nameLabel;
}
- (UILabel *)songLabel{
    if (_songLabel == nil) {
        _songLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 28, 120, 20)];
        _songLabel.text = @"歌曲名";
        _songLabel.font = [UIFont systemFontOfSize:11];
        _songLabel.textColor = [UIColor colorWithWhite:0.8 alpha:1];
    }
    return _songLabel;
}
- (UIButton *)downBtn{
    if (_downBtn == nil) {
        _downBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _downBtn.frame = CGRectMake(215, 10, 40, 40);
        [_downBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    }
    return _downBtn;
}
- (UIButton *)likeBtn{
    if (_likeBtn == nil) {
        _likeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _likeBtn.frame = CGRectMake(265, 10, 40, 40);
        [_likeBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [_likeBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateSelected];
    }
    return _likeBtn;
}
- (UIButton *)playBtn{
    if (_playBtn == nil) {
        _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _playBtn.frame = CGRectMake(125, 70, 70, 70);
        [_playBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [_playBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateSelected];
    }
    return _playBtn;
}
- (UIButton *)randomBtn{
    if (_randomBtn == nil) {
        _randomBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _randomBtn.frame = CGRectMake(15, 87, 40, 40);
        [_randomBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    }
    return _randomBtn;
}
- (UIButton *)backBtn{
    if (_backBtn == nil) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _backBtn.frame = CGRectMake(65, 85, 40, 40);
        [_backBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    }
    return _backBtn;
}
- (UIButton *)nextBtn{
    if (_nextBtn == nil) {
        _nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _nextBtn.frame = CGRectMake(215, 85, 40, 40);
        [_nextBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    }
    return _nextBtn;
}
- (UIButton *)shareBtn{
    if (_shareBtn == nil) {
        _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _shareBtn.frame = CGRectMake(265, 82, 50, 50);
        [_shareBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    }
    return _shareBtn;
}
- (UIView *)playControlView{
    if (_playControlView == nil) {
        _playControlView = [[UIView alloc] initWithFrame:CGRectMake(0, 414, 320, 154)];
        _playControlView.backgroundColor = [UIColor grayColor];
        [_playControlView addSubview:self.nameLabel];
        [_playControlView addSubview:self.songLabel];
        [_playControlView addSubview:self.downBtn];
        [_playControlView addSubview:self.likeBtn];
        [_playControlView addSubview:self.pageCtrl];
        [_playControlView addSubview:self.slider];
        [_playControlView addSubview:self.playBtn];
        [_playControlView addSubview:self.randomBtn];
        [_playControlView addSubview:self.backBtn];
        [_playControlView addSubview:self.nextBtn];
        [_playControlView addSubview:self.shareBtn];
        [_playControlView addSubview:self.curtimeLabel];
        [_playControlView addSubview:self.durationLabel];
    }
    return _playControlView;
}
// 当前播放时间标签
-(UILabel *)curtimeLabel
{
    if (!_curtimeLabel) {
        _curtimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 75, 40, 15)];
        _curtimeLabel.font = [UIFont systemFontOfSize:10];
        _curtimeLabel.textColor = [UIColor whiteColor];
    }
    return _curtimeLabel;
}
// 音乐持续时间标签
-(UILabel *)durationLabel
{
    if (!_durationLabel) {
        _durationLabel = [[UILabel alloc] initWithFrame:CGRectMake(285, 75, 30, 15)];
        _durationLabel.font = [UIFont systemFontOfSize:10];
        _durationLabel.textColor = [UIColor whiteColor];
    }
    return _durationLabel;
}
#pragma mark -  控件触发事件
-(void)pageCtlDidHandle:(UIPageControl *)sender
{
    // 获得当前分页
    NSInteger curPage = sender.currentPage;
    CGRect frame = self.scrollView.frame;
    // 设置滚动视图需要滚到的区域
    CGRect toRect = CGRectMake(frame.size.width  * curPage, frame.origin.y, frame.size.width, frame.size.height);
    // 改变滚动视图
    [self.scrollView scrollRectToVisible:toRect animated:YES];  
}
#pragma mark - UIScrollViewDelegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // 获得当前分页
    NSInteger curPage = fabs(scrollView.contentOffset.x / 320);
    self.pageCtrl.currentPage = curPage;
}
#pragma mark - ViewLoad
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.scrollView];
        [self addSubview:self.playControlView];
        
        self.pageCtrl.currentPage = 1;
        self.scrollView.contentOffset = CGPointMake(320, 0);
        
    }
    return self;
}


转载于:https://my.oschina.net/suyongchen/blog/672463

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值