zoukankan      html  css  js  c++  java
  • swift UISwitch,UISegmentedControl

    //

    //  SegmentedControl.swift

    //  UIControlDemo

    //

    //  Created by   on 14/12/1.

    //  Copyright (c) 2014 马大哈. All rights reserved.

    //

     

    import UIKit

     

    class SegmentedControl: BaseViewController {

        

        var  colorSegment: UISegmentedControl?

        var colorSwitch:UISwitch?

     

        override func viewDidLoad() {

            super.viewDidLoad()

            

            self.title = "UISegmentedControl+UISwitch"

            

            self.view.backgroundColor = UIColor.redColor()

            

            var colorArray = ["","","",""];

            

            colorSegment = UISegmentedControl(items: colorArray)

            colorSegment?.frame = CGRectMake(30, 100, self.view.frame.size.width-60,40)

            colorSegment?.selectedSegmentIndex = 0

            colorSegment?.addTarget(self, action: "changeColor:", forControlEvents: UIControlEvents.ValueChanged)

            self.view.addSubview(colorSegment!)

            

            // UISwitch width height都是系统锁定的默认值,无法通过frame修改

            colorSwitch = UISwitch(frame: CGRectMake(30, 170, 100,40))

            colorSwitch?.on = false

            colorSwitch?.onTintColor = UIColor.blackColor()

            colorSwitch?.tintColor = UIColor.blueColor()

            colorSwitch?.addTarget(self, action: "openClose:", forControlEvents: .ValueChanged)

            self.view.addSubview(colorSwitch!)

     

            

        }

        

        

        

        func changeColor(segment:UISegmentedControl){

            

            switch segment.selectedSegmentIndex{

                

            case 0:

                self.view.backgroundColor = UIColor.redColor()

                

            case 1:

                self.view.backgroundColor = UIColor.yellowColor()

                

            case 2:

                self.view.backgroundColor = UIColor.blueColor()

                

            case 3:

                self.view.backgroundColor = UIColor.blackColor()

                

            default:

                self.view.backgroundColor = UIColor.whiteColor()

                

            }

            

            

        }

     

        

        func openClose(open:UISwitch){

           

    //        colorSegment?.hidden = open.on

     

            if open.on{

                colorSegment?.hidden = true

            }else{

                colorSegment?.hidden = false

            }

            

        }

         

        override func didReceiveMemoryWarning() {

            super.didReceiveMemoryWarning()

            // Dispose of any resources that can be recreated.

        }

        

        

    }

     

  • 相关阅读:
    好物推荐,码出高效
    C#设置session过期时间
    [C#] Request.QueryString()测试:用html而非asp控件实现简单登录验证并保存值到Session中
    .aspx页面 用html按钮传送数据到 .aspx.cs后台的和“利用Ajax连接aspx与aspx.cs”方法记录
    Visual Studio出现“ 激活远程语言服务器 c#/Visual Basic 语言服务器客户端出错”请运行devenv/log并检查…………“错误解决办法
    解决ubuntu server下屏幕显示不全问题的详解
    关于ubuntu选择desktop版本还是sever版本的一篇随笔
    MAC系统npm安装依赖,报错npm ERR! code ECONNREFUSED
    Linux 常用命令总结
    Mac电脑查询IP
  • 原文地址:https://www.cnblogs.com/madaha/p/4143771.html
Copyright © 2011-2022 走看看