美文网首页
Swift开发笔记

Swift开发笔记

作者: Look2021 | 来源:发表于2019-03-27 19:45 被阅读0次

    iOS13适配

    public func clearBlackLine() {
        for view in self.subviews.last!.subviews {
            if view.isKind(of: NSClassFromString("UISearchBarBackground")!) {
                view.backgroundColor = UIColor.white
                view.layer.contents = nil
                break
            }
        }
    }
    

    Int、UInt

    整数分为2种类型

    • 有符号Int:正、负、零
    • 无符号UInt:正、零
    Int8占1字节,-128 127x
    Int16, 等于short, 占2个字节. -32768 32767
    Int32, 等于int, 占4个字节. -2147483648 2147483647
    Int64, 等于long, 占8个字节. -9223372036854775808 9223372036854775807
    Int长度与当前平台的原生字长相同
    

    override

    required init?(coder aDecoder: NSCoder) {
    return nil
    }

    convenience

    Array

    cell.textLabel?.text = (tableData[indexPath.row] as! [String : String])["title"]
    

    UIView

    // 设置阴影
    layer.shadowOffset = CGSize.init(width: 0, height: 1)
    layer.shadowColor = UIColor.darkBlackColor.cgColor
    layer.shadowOpacity = 0.3
    
    // 设置围框
    backView.layer.borderWidth = 0.5
    backView.layer.borderColor = UIColor.placeholderColor.cgColor
    backView.layer.masksToBounds = true
    

    UIImage,UIImageView

    UIImageView的填充模式
    scaleToFill - 拉伸充满整个载体
    scaleAspectFit - 拉伸不改变比例,充满最小的一边
    scaleAspectFill - 拉伸不改变比例,充满最大的一边
    
    // 设置图片重复填充满imageView
    if let image = UIImage.init(named: "home_quality_shadingsmall") {
        textureImageView.backgroundColor = UIColor.init(patternImage: image)
    }
    
    // 设置图片以中心点拉大填充imageView,四个角的像素不会改变,类似聊天气泡
    let backImage = UIImage.init(named: "home_quality_backimage")
            if let height = backImage?.size.height, let width = backImage?.size.width {
                let edge = UIEdgeInsets.init(top: height / 2 - 0.5, left: width / 2 - 0.5, bottom: height / 2 - 0.5, right: width / 2 - 0.5)
                backImage?.resizableImage(withCapInsets: edge, resizingMode: UIImage.ResizingMode.stretch)
    }
    
    extension GGGoodsActivityDetailsTableCell: UICollectionViewDelegate, UICollectionViewDataSource {
        
        func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            return 20
        }
        
        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            
            let cell = collectionView.ts_dequeueReusableCell(GGGoodsActivityDetailsCollectionCell.self, forIndexPath: indexPath)
            return cell!
        }
        
        func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
            
            let vc = GGGoodsDetailsViewController.init()
            CommonTool.getTopVC()?.navigationController?.pushViewController(vc, animated: true)
        }
    }
    

    Array

    使用布尔量 isEmpty属性来作为检查 count属性是否等于 0的快捷方式

    if shoppingList.isEmpty {
        print("The shopping list is empty.")
    }
    

    UIButton

    // 取消按钮高亮效果
    searchButton.adjustsImageWhenHighlighted = false
    

    Switch

    Switch 选择语句支持任意类型的数据和各种类型的比较操作——它不再限制于整型和测试相等上。

    Swift没有分类

    Protocol

    类,枚举以及结构体都兼容协议。
    mutating

    RxSwift

    PublishSubject
    1.PublishSubject是最普通的 Subject,它不需要初始值就能创建。
    2.PublishSubject 的订阅者从他们开始订阅的时间点起,可以收到订阅后 Subject 发出的新 Event,而不会收到他们在订阅前已发出的 Event。

    // 遍历拿到数组里的某个值形成的数组
    self.segmentedDataSource.titles = model.map { $0.categoryName ?? "" }
    

    拨打电话

    let url = URL(string: "tel:10086")!
                    if #available(iOS 11, *) {
                        UIApplication.shared.openURL(url)
                    } else {
                        let alertVC = UIAlertController(title: "提示", message: "确认拨打电话吗?", cancelTitle: "取消", otherTitles: ["确定"], style: .alert, doneClosure: { _ in
                            UIApplication.shared.openURL(url)
                        })
                        self?.present(alertVC, animated: true, completion: nil)
                    }
    

    weak 和 unowned

    根据属性是否为可选类型,你可以在 weak 和 unowned 之间进行选择。

    UISwitch

    lazy var uiSwitch: UISwitch = {
            let uiSwitch = UISwitch.init()
            uiSwitch.transform = CGAffineTransform.init(scaleX: 0.6, y: 0.6)
            //设置默认值
            uiSwitch.backgroundColor = .Color_DADADA
            uiSwitch.tintColor = UIColor.Color_DADADA//Switch 边框颜色
            uiSwitch.onTintColor = UIColor.themeColor//Switch为on时候的颜色
            uiSwitch.cornerRadius = uiSwitch.height / 0.6 / 2
            return uiSwitch
        }()
    
    图表库
    
    Android
    https://github.com/PhilJay/MPAndroidChart
    https://github.com/blackfizz/EazeGraph
    https://github.com/lecho/hellocharts-android
    https://github.com/AnyChart/AnyChart-Android
    https://github.com/HackPlan/AndroidCharts
    https://github.com/xcltapestry/XCL-Charts
    
    iOS 
    https://github.com/danielgindi/Charts
    https://github.com/AAChartModel/AAChartKit
    https://github.com/kevinzhow/PNChart
    https://github.com/xhacker/TEAChart
    https://github.com/i-schuetz/SwiftCharts
    https://github.com/gpbl/SwiftChart
    
    h5
    https://frappe.io/charts
    https://echarts.apache.org/examples/zh/index.html
    https://www.chartjs.org/samples/latest/
    https://github.com/d3/d3/wiki/Gallery
    http://gionkunz.github.io/chartist-js/examples.html
    https://plot.ly/javascript/
    https://www.highcharts.com/demo
    https://c3js.org
    

    相关文章

      网友评论

          本文标题:Swift开发笔记

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