//
// ViewController.swift
// demo
//
// Created by 刘波 on 2017/8/9.
// Copyright © 2017年 Liu. All rights reserved.
//
import UIKit
class asdViewController: UIViewController {
var flag = true
var view1: UIView!
var view2: UIView!
let width = UIScreen.main.bounds.width
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
view.backgroundColor = UIColor.white
view1 = UIView(frame: CGRect(x: 0, y: 74, width: width, height:100))
view1.backgroundColor = UIColor.red
let btn = generateBtn(frame: CGRect(x:0, y: 0, width: self.view.bounds.width, height: 40),tag: 1)
let label2 = UILabel(frame: CGRect(x: 0, y: 10, width: 50, height: 20))
label2.text = "2343234234234"
let tewxt = UITextField(frame: CGRect(x: 0, y: 50, width: self.view.bounds.width, height: 20))
tewxt.layer.borderWidth = 1
let btn2 = generateBtn(frame: CGRect(x:0, y: 0, width: self.view.bounds.width, height:40),tag: 2)
view2 = UIView(frame: CGRect(x: 0, y: 174, width: width, height:40))
view2.backgroundColor = UIColor.blue
let label3 = UILabel(frame: CGRect(x: 0, y: 10, width: 50, height: 20))
label3.text = "23234"
view1.addSubview(label2)
view1.addSubview(tewxt)
view2.addSubview(label3)
view1.addSubview(btn)
self.view.addSubview(view1)
view2.addSubview(btn2)
self.view.addSubview(view2)
}
func generateBtn(frame:CGRect,tag:Int) ->UIButton{
let btn = UIButton(type: .custom)
btn.frame = frame
btn.layer.borderWidth = 1
btn.backgroundColor = UIColor.white
btn.tag = tag
btn.layer.borderColor = UIColor( red:0, green:0, blue:0, alpha:0.2 ).cgColor
btn.addTarget(self, action: #selector(btn_click(_:)), for: .touchUpInside)
let imag = UIImageView(image:UIImage(named:"customer_0001_-2"))
imag.frame = CGRect(x:0, y:20, width:15, height:0)
imag.frame.origin.x = self.view.bounds.width - imag.frame.width-20
imag.contentMode = UIViewContentMode.scaleAspectFill
btn.addSubview(imag)
return btn
}
func btn_click(_ sender: UIButton){
if sender.tag == 1 {
//self.view1.isHidden = !flag
if flag{
self.view1.frame = CGRect(x: 0, y: 74, width: width, height: 40)
self.view2.frame = CGRect(x: 0, y: 124, width: width, height: 40)
}else{
self.view1.frame = CGRect(x: 0, y: 74, width: width, height: 100)
self.view2.frame = CGRect(x: 0, y: 174, width: width, height: 40)
}
}
if sender.tag == 2 {
if flag{
self.view1.frame = CGRect(x: 0, y: 74, width: width, height: 40)
self.view2.frame = CGRect(x: 0, y: 124, width: width, height:100)
}else{
self.view1.frame = CGRect(x: 0, y:74, width: width, height: 40)
self.view2.frame = CGRect(x: 0, y: 124, width: width, height:40)
}
}
flag = !flag
// btn.isSelected = !btn.isSelected
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}