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;

        }

        

    }

  • 相关阅读:
    Flash 全局安全性设置面板
    响应式布局的一个例子mark
    移动平台WEB前端开发技巧汇总
    自定义事件机制——观察者模式
    学习之响应式Web设计:Media Queries和Viewports
    常用栅格布局方案
    观察者模式的一个例子
    二进制文件转换为文本工具
    C#面向对象名词比较(二)
    MSN消息提示类
  • 原文地址:https://www.cnblogs.com/anjiubo/p/5259772.html
Copyright © 2011-2022 走看看