zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    自己写的DBHelper感慨颇深
    23种设计模式:观察者模式,第一次对观察者模式理解的这么通透。
    自己用心写的 存储过程分页 给自己的平台用
    开篇成长的开始[废话一把]
    C# 中i++在ref参数调用下的有趣现象
    点点滴滴的成长[2011111]:理解C#修饰符
    点点滴滴的成长[2011114]:自定义config文件
    扩展方法在Json字符串转化中的应用
    jquery学习二:jquery性能优化
    javascript系列1:函数
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5676620.html
Copyright © 2011-2022 走看看