美文网首页iOS开发札记
2019-03-07:iOS开发札记

2019-03-07:iOS开发札记

作者: QxyBest | 来源:发表于2019-03-08 10:13 被阅读0次

知识点:

  1. UIApplication.shared.isNetworkActivityIndicatorVisible = true
    是否在顶部状态栏显示网络状态(转圈圈表示网络未接入)
  2. 在编辑器添加UIColor 时可以选择自动补全的 color literal,就可以打开颜色编辑器了

代码片段

用代码定义有事件的按钮:

btnAdd.addTarget(self, action: #selector(addView(_:)), for: .touchUpInside)

@objc func addView(_ sender:UIButton){
        let rectView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
        rectView.backgroundColor = UIColor.green
        
        view.addSubview(rectView)
}

给View添加边框效果:

btnAdd.layer.borderWidth = 10
btnAdd.layer.borderColor = UIColor.red.cgColor
btnAdd.layer.cornerRadius = 20
btnAdd.layer.masksToBounds = true

给VIew添加阴影效果:

imageView.layer.shadowColor = UIColor.gray.cgColor
imageView.layer.shadowOffset = CGSize(width: 10, height: 10)
imageView.layer.shadowOpacity = 0.5
imageView.layer.shadowRadius = 10

给View添加渐变颜色:

        let gradienLayer = CAGradientLayer()
        gradienLayer.frame = imageView.frame
        
        let redColor = UIColor.red.cgColor
        let greenColor = UIColor.green.cgColor
        let blueColor = UIColor.blue.cgColor
        
        gradienLayer.colors = [redColor,blueColor,greenColor]
        
        imageView.layer.addSublayer(gradienLayer)

给View类设置纹理填充

        let image = UIImage(named: "paper")
        let patternColor = UIColor(patternImage: image!)
        imageView.backgroundColor = patternColor

给View类设置点击事件(单点,双点,长按)

        let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPress(_:)))
        
        let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(doubleTap(_:)))
        doubleTapGesture.numberOfTouchesRequired = 1
        doubleTapGesture.numberOfTapsRequired = 2
        
        imageView.isUserInteractionEnabled = true
        
        imageView.addGestureRecognizer(longPressGesture)
        imageView.addGestureRecognizer(doubleTapGesture)
        
        view.addSubview(imageView)

    @objc func longPress(_ gesture : UILongPressGestureRecognizer){
        if gesture.state == .began{
            let alert = UIAlertController(title: "Information", message: "Long Message", preferredStyle: .alert)
            let OKAction = UIAlertAction(title: "OK", style: .default, handler: nil)
            alert.addAction(OKAction)
            self.present(alert, animated: true, completion: nil)
        }
    }
    
    @objc func doubleTap(_ gesture : UITapGestureRecognizer){
        let alert = UIAlertController(title: "Information", message: "Double Tap", preferredStyle: .alert)
        let OKAction = UIAlertAction(title: "OK", style: .default, handler: nil)
        alert.addAction(OKAction)
        self.present(alert, animated: true, completion: nil)
    }

相关文章

  • 2019-03-07:iOS开发札记

    知识点: UIApplication.shared.isNetworkActivityIndicatorVisib...

  • 04_C#学习_面向对象

    2019-03-07 面向对象编程 特点:封装,继承,多态(子类)优点:易维护,易扩展,易开发—— 与面向过程编程...

  • 2019-03-07

    2019-03-07

  • iOS开发优秀博客和软件推荐

    iOSBlogAndTools iOS开发优秀博客和软件推荐 iOS开发中文博客 iOS开发工具 iOS开发网站 ...

  • 收录 : iOS支付开发

    iOS 银联支付开发流程iOS 微信支付开发流程iOS 支付宝支付开发流程iOS Apple Pay开发流程App...

  • IOS开发问题索引(四)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

  • IOS开发问题索引(八)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

  • IOS开发问题索引(七)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

  • IOS开发问题索引(六)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

  • IOS开发问题索引(五)

    全系列文章索引: IOS开发问题索引(一) IOS开发问题索引(二) IOS开发问题索引(三) IOS开发问题索引...

网友评论

    本文标题:2019-03-07:iOS开发札记

    本文链接:https://www.haomeiwen.com/subject/oxdcpqtx.html