• UI基础--UISlider&UIProgress


    声明属性:

    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    
    {
        //滑动条(音量)
        UISlider *_slider;
        //进度条对象(一般表示进度)
        UIProgressView *_progressView;
    }
    
    //进度条
    @property (nonatomic, strong) UIProgressView * pView;
    //滑动条
    @property (nonatomic, strong) UISlider *slid;
    
    @end

    创建对象:

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    //同步成员变量和属性
    @synthesize slid = _slider;
    @synthesize pView = _pView;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        //设置背景颜色
        self.view.backgroundColor = [UIColor yellowColor];
        
        //进度条的创建(不能主动的添加事件)
        _progressView = [[UIProgressView alloc]init];
        //设置进度条的大小和位置(高度是不可变化的)
        _progressView.frame = CGRectMake(10, 50, 300, 10);
        
        //设置进度条的风格颜色值
        _progressView.progressTintColor = [UIColor redColor];
        
        //设置进度条的进度值(0--1)
        _progressView.progress = 0.5;
        //设置进度条的风格
        _progressView.progressViewStyle = UIProgressViewStyleDefault;
        
        _progressView.trackTintColor = [UIColor blackColor];
        
        //添加到当前视图上面
        [self.view addSubview:_progressView];
        
        
        
        _slider = [[UISlider alloc]init];
        _slider.frame = CGRectMake(10, 100, 300, 40);
        
        //设置最大值
        _slider.maximumValue = 100;
        //设置最小值(可以为负值)
        _slider.minimumValue = -100;
        
        //设置滑动条滑块的位置
        _slider.value = 0.5;
        
        //滑块左侧颜色
        _slider.minimumTrackTintColor = [UIColor lightGrayColor];
        //滑块右侧颜色
        _slider.maximumTrackTintColor = [UIColor redColor];
        
        //设置滑块的颜色
        _slider.thumbTintColor = [UIColor purpleColor];
        
        //添加滑块滑动事件
        [_slider addTarget:self action:@selector(SliderAct:) forControlEvents:UIControlEventValueChanged];
        
        [self.view addSubview:_slider];
        
        
    }
    
    - (void)SliderAct:(UISlider *)slider{
        
        NSLog(@"value = %.2f", slider.value);
        //滑动滑块改变进度条的位置
    //    _progressView.progress = slider.value;
        //如果值超出范围,需要写个个算法
        _progressView.progress = (slider.value - slider.minimumValue) / (_slider.maximumValue - slider.minimumValue);
        
        
        
        
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    安卓小助手
    位图切割器&位图裁剪器
    OAuth2.0 的简介
    多账户的统一登录方案
    常用的一些SQL语句
    SQL语句的优化
    SpringCloud简介与5大常用组件
    数据库为什么需要锁机制?有哪些锁机制?
    高并发下如何优化能避免服务器压力过大?
    Spring MVC 简介
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5676620.html
Copyright © 2020-2023  润新知