zoukankan      html  css  js  c++  java
  • IOS开发中用开关(UISwitch)跟滑块(UISlider)控制手机屏幕的亮度

    .h文件

    #import <UIKit/UIKit.h>

    @interface ViewController : UIViewController

    @property(strong,nonatomic)UISlider *mysld;

    @property(strong,nonatomic)UISwitch *myswitch;

    @property(strong,nonatomic)UIImageView *imageview;

    @end

     .m文件

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.imageview=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"phone.jpg" ]];

        self.imageview.frame=self.view.bounds;

        self.imageview.autoresizingMask=UIViewAutoresizingFlexibleWidth;

        [self.view insertSubview:self.imageview atIndex:0];

        

        //创建一个滑块

        self.mysld=[[UISlider alloc]initWithFrame:CGRectMake(100, 200, 250, 50)];

        [self.view addSubview:self.mysld];

        //创建一个开关

        self.myswitch=[[UISwitch alloc]initWithFrame:CGRectMake(150, 100, 150, 150)];

        [self.view addSubview:self.myswitch];

        

        [self.myswitch addTarget:self action:@selector(changevalue) forControlEvents:UIControlEventValueChanged];

        [self.mysld addTarget:self action:@selector(textvalue) forControlEvents:UIControlEventValueChanged];

    }

    -(void)changevalue

    {

        

        if (self.myswitch.isOn) {

            //设置屏幕默认亮度为0.5

            [self.mysld setValue:0.5];

           self.imageview.alpha=self.mysld.value;

    } else

        {

        

            [self.mysld setValue:0.0];

            self.imageview.alpha=self.mysld.value;

        }

    }

    -(void)textvalue

    {

        if (self.myswitch.isOn) {

            self.imageview.alpha=self.mysld.value;

        }

        

    }

  • 相关阅读:
    js封装日期格式化函数
    原生js时间戳获取和转换
    自适应好用的一个css
    ES6五种遍历对象属性的方式
    ES6对象属性名简洁表示法和表达式、对象新方法、属性的遍历
    ES6数组扩展运算符(Rest+Spread)、类方法、原型方法
    正则表达式常见匹配
    typescript深copy和浅copy
    判断一个变量类型是对象还是数组
    npm 淘宝镜像的配置
  • 原文地址:https://www.cnblogs.com/anjiubo/p/5259772.html
Copyright © 2011-2022 走看看