iOS uibutton 上下按钮样式

本文介绍了一种在iOS应用中实现直播视频分辨率切换的方法。通过使用两个按钮来切换高、低分辨率,根据当前摄像头分辨率的不同调整按钮显示的文字,并在点击按钮后调用切换分辨率的方法。

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

@implementation HBLiveStreamView

{

    BOOL _isHigh;

    BOOL _isLow;

    CGRect overBtnFrame;

    CGRect belowBtnFrame;

}

// 放两个视频分辨率按钮的view

    self.resolutionView = [[UIView alloc]init];

    [self.resolutionView setFrame:CGRectMake(self.width-100, self.height-93, 50, 100)];

    [self.toolView addSubview:self.resolutionView];

    

    //上面分辨率按钮  下面按钮的frame = CGRectMake(15, 60, 30, 30) 下面按钮的frame = CGRectMake(15, 30, 30, 30)

    self.aboveButton = [[UIButton alloc]init];

    [self.aboveButton setFrame:CGRectMake(15, 30, 30, 30)];

    overBtnFrame = self.aboveButton.frame;

    [self.aboveButton addTarget:self action:@selector(showHighResolutionBtn:) forControlEvents:UIControlEventTouchUpInside];

    self.aboveButton.titleLabel.textColor =[UIColor whiteColor];

    self.aboveButton.titleLabel.textAlignment = NSTextAlignmentCenter;

    [self.aboveButton.titleLabel setFont:[UIFont systemFontOfSize:10]];

    [self.aboveButton setBackgroundColor:RGBACOLOR(0, 0, 0, 0.8)];

    [self.aboveButton setHidden:YES];

    [self.resolutionView addSubview:self.aboveButton];

    

    //下面分辨率按钮

    self.belowButton = [[UIButton alloc]init];

    [self.belowButton setFrame:CGRectMake(15, 60, 30, 30)];

    belowBtnFrame = self.belowButton.frame;

    [self.belowButton addTarget:self action:@selector(showLowResolutionBtn:) forControlEvents:UIControlEventTouchUpInside];

    self.belowButton.titleLabel.textColor =[UIColor whiteColor];

    self.belowButton.titleLabel.textAlignment = NSTextAlignmentCenter;

    [self.belowButton.titleLabel setFont:[UIFont systemFontOfSize:10]];

    [self.belowButton setBackgroundColor:RGBACOLOR(0, 0, 0, 0.8)];


    [self.resolutionView addSubview:self.belowButton];

    

    if([[DeviceManager shareInstace].currentCamera.resolution isEqualToString:@"720"]){//从服务器获得720P  [DeviceManager shareInstace].currentCamera.resolution

        [self.aboveButton setTitle:@"480P" forState:UIControlStateNormal];

        [self.aboveButton setTitle:@"480P" forState:UIControlStateHighlighted];

        [self.belowButton setTitle:@"720P" forState:UIControlStateNormal];

        [self.belowButton setTitle:@"720P" forState:UIControlStateHighlighted];

    }else{          //从服务器获得480P [DeviceManager shareInstace].currentCamera.resolution

        [self.aboveButton setTitle:@"720P" forState:UIControlStateNormal];

        [self.aboveButton setTitle:@"720P" forState:UIControlStateHighlighted];

        [self.belowButton setTitle:@"480P" forState:UIControlStateNormal];

        [self.belowButton setTitle:@"480P" forState:UIControlStateHighlighted];

    }


/**

 *  点击下面按钮

 */

- (void)showLowResolutionBtn:(UIButton *)btn{

    

    if (_isHigh) {  //再次点击下面,隐藏上面按钮

        [self.aboveButton setHidden:YES];

        if ([NSStringFromCGRect(self.belowButton.frame) isEqualToString:NSStringFromCGRect(overBtnFrame)])

        {

            self.belowButton.frame = belowBtnFrame;

            self.aboveButton.frame = overBtnFrame;

            //切换到另一种画质

            [self changeResolution:btn];

        }

    }else// 初次点击下面,显示上面按钮

        [self.aboveButton setHidden:NO];

        

    }

    _isHigh =!_isHigh;

}

/**

 *  点击上面按钮

 */

- (void)showHighResolutionBtn:(UIButton *)btn{

    

    if (_isLow) {   //再次点击480P按钮,显示720P按钮

        self.belowButton.frame = overBtnFrame;

        [self.belowButton setHidden:NO];

        

    }else// 初次点击,设置480下面,隐藏720P按钮

        //切换到480P

        if ([NSStringFromCGRect(self.aboveButton.frame) isEqualToString:NSStringFromCGRect(overBtnFrame)])

        {

            //切换到另一种画质

            [self changeResolution:btn];

        }

        self.aboveButton.frame = belowBtnFrame;

        [self.belowButton setHidden:YES];

    }

    _isLow =!_isLow;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值