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;

        }

        

    }

  • 相关阅读:
    【次大gcd】#uoj #48. 【UR #3】核聚变反应强度
    1591:数字计数
    数位DP模板
    1588:数字游戏
    [NOIP 2017普及组 No.1] 成绩
    [NOIP 2017普及组 No.3] 棋盘
    Apache(httpd)实现反向代理
    注册阿里云域名
    SSH常用命令
    Linux yum 安装Java和MySQL
  • 原文地址:https://www.cnblogs.com/anjiubo/p/5259772.html
Copyright © 2011-2022 走看看