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;

        }

        

    }

  • 相关阅读:
    8.14 每日课后作业系列之RE正则 模块的运用
    8.13 每日课后作业系列之hashlib shelve xml模块的运用
    8.10 每日课后作业系列之包的建立
    8.9 每日课后作业系列之进度条 and 验证码
    操作系统与python入门
    计算机硬件基础
    MySQL系列
    html5和css (四 布局新增)
    html5和css(三 页面布局)
    html5和css(二 页面组成)
  • 原文地址:https://www.cnblogs.com/anjiubo/p/5259772.html
Copyright © 2011-2022 走看看