ios swift UI控件 --- 持续更新中

一、UILabel 

 var label:UILabel?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.whiteColor()
        self.title = "UILabel 使用常用属性"
        // Do any additional setup after loading the view.
        
        // 初始化 并设置位置
        self.label = UILabel(frame: CGRect(x:50, y:100, width:200, height:100))
        self.view!.addSubview(self.label!)
        self.label?.backgroundColor = UIColor.yellowColor()
        self.label?.text = "Marico Label"
        self.label?.alpha = 0.5
        self.label?.textAlignment = NSTextAlignment.Center
        self.label?.font = UIFont(name: "Thonburi", size: 13)
//        self.label?.textColor = UIColor(white: 1, alpha: 1)
        self.label?.textColor = UIColor.blueColor()
        self.label?.adjustsFontSizeToFitWidth = true
        self.label?.numberOfLines = 1
        self.label?.shadowColor = UIColor.redColor()
        self.label?.shadowOffset = CGSize(width: 1, height: 1)
        self.label?.clipsToBounds = true
        self.label?.layer.cornerRadius = 10
        self.label?.layer.masksToBounds = true
    }

二、UIButton

var button:UIButton?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.whiteColor()
        // Do any additional setup after loading the view.
        self.button = UIButton(type: UIButtonType.RoundedRect)
        self.button?.frame = CGRect(x: 100, y: 100, width: 100, height: 60)
        self.button?.backgroundColor = UIColor.blueColor()
        self.button?.setTitle("Marico", forState: UIControlState.Normal)
        self.view.addSubview(self.button!)
        self.button?.addTarget(self, action: #selector(buttonClick(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        self.button?.tag = 100
        self.button?.setImage(UIImage(named: "关按钮"), forState: UIControlState.Normal)
        self.button?.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
    }
    func buttonClick(button:UIButton) {
        print(button.titleForState(UIControlState.Normal))
        print(button.tag)
//        常用的触摸事件类型:
//        TouchDown:单点触摸按下事件,点触屏幕
//        TouchDownRepeat:多点触摸按下事件,点触计数大于1,按下第2、3或第4根手指的时候
//        TouchDragInside:触摸在控件内拖动时
//        TouchDragOutside:触摸在控件外拖动时
//        TouchDragEnter:触摸从控件之外拖动到内部时
//        TouchDragExit:触摸从控件内部拖动到外部时
//        TouchUpInside:在控件之内触摸并抬起事件
//        TouchUpOutside:在控件之外触摸抬起事件
//        TouchCancel:触摸取消事件,即一次触摸因为放上太多手指而被取消,或者电话打断
    }

 三、UIImageView

var imageView:UIImageView?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white()
        // Do any additional setup after loading the view.
        let imageName = "湖面青松.jpg"
        let image_one = UIImage(named: imageName)
//        self.imageView = UIImageView(frame: CGRect(x: 0, y: 84, width: (image_one?.size.width)!, height: (image_one?.size.height)!))
        self.imageView = UIImageView(frame: CGRect(x: 0, y: 64, width: (self.view.bounds.size.width), height: 200))
        self.view.addSubview(self.imageView!)
        self.imageView?.image = image_one
        // 添加手势
        self.imageView?.isUserInteractionEnabled = true
        let target = UITapGestureRecognizer(target: self, action: #selector(tageClick))
        self.imageView?.addGestureRecognizer(target)
    }
func tageClick() { print(
"触发手势") }

 代码地址:https://github.com/marico-sun/NDSwift.git

posted @ 2016-07-25 22:40  MaricoSun  阅读(2704)  评论(0)    收藏  举报