zoukankan      html  css  js  c++  java
  • iOS

    前言

    	NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UISwitch : UIControl <NSCoding>
    	@available(iOS 2.0, *)						   public class UISwitch : UIControl, NSCoding
    

    1、Switch 的创建

    • Objective-C

      	// 实例化 switch 对象,switch 的大小是由系统固定的
      	UISwitch *switch1 = [[UISwitch alloc] init];
      
      	// 将 sw 添加到 view
      	[self.view addSubview:switch1];
      
    • Swift

      	// 实例化 switch 对象,switch 的大小是由系统固定的
      	let switch1:UISwitch = UISwitch()
      
      	// 将 sw 添加到 view
      	self.view.addSubview(switch1)
      

    2、Switch 的设置

    • Objective-C

      	// 设置位置
      	switch1.center = self.view.center;
      	    
      	// 设置 tag 值
      	switch1.tag = 100;
      	    
      	// 设置外边框颜色
      	switch1.tintColor = [UIColor redColor];
      	    
      	// 设置滑块的颜色
      	switch1.thumbTintColor = [UIColor blueColor];
      	    
      	// 设置 on 时的颜色
      	/*
      		默认为绿色
      	*/
      	switch1.onTintColor = [UIColor orangeColor];
      	    
      	// 设置当前的开关状态
      	switch1.on = YES;
      	    
      	// 获取当前的开关状态
      	BOOL isOn = switch1.isOn;
      	   	
      	// 添加点击触发事件
      	[switch1 addTarget:self action:@selector(switchClick:) forControlEvents:UIControlEventValueChanged];
      
    • Swift

      	// 设置位置
      	switch1.center = self.view.center
      	    
      	// 设置 tag 值
      	switch1.tag = 100
      	    
      	// 设置外边框颜色
      	switch1.tintColor = UIColor.redColor()
      	    
      	// 设置滑块的颜色
      	switch1.thumbTintColor = UIColor.blueColor()
      	    
      	// 设置 on 时的颜色
      	/*
      		默认为绿色
      	*/
      	switch1.onTintColor = UIColor.orangeColor()
      	    
      	// 设置当前的开关状态
      	switch1.on = true
      	    
      	// 获取当前的开关状态
      	let isOn:Bool = switch1.on
      	  	
      	// 添加点击触发事件
      	switch1.addTarget(self, action: #selector(UiSwitch.switchClick(_:)), forControlEvents: .ValueChanged)
      

    3、Storyboard 中设置

    • 在 Storyboard 场景中设置

      • Switch 设置

        Switch1

        State 开关状态
          			  |
        

        On Tint | 开关开时的颜色
        Thumb Tint | 开关滑块的颜色
        |
        On Image | 开关开时的图片
        Off Image | 开关关时的图片

      • Control 设置

        Switch2

        Alignment 文字对齐方式
          			    |
        

        Content |
        -- Selected | 选中
        -- Enable | 可用
        -- Highlighted | 高亮

  • 相关阅读:
    CTF-1-5题笔记
    无相劫指:Web安全之其他专题—第七天
    七伤拳:Web安全之文件包含漏洞专题—第六天
    CTF-输入密码查看flag -80
    工业级路由器采用的协议和功能
    PLC模拟量采集模块在工控领域的应用
    串口服务器的作用和工作原理是什么
    在PLC中开关量采集模块的作用
    4G DTU和4G工业路由器有哪些区别?
    应该怎么提升4G工业路由器的无线信号?
  • 原文地址:https://www.cnblogs.com/QianChia/p/5755168.html
Copyright © 2011-2022 走看看