美文网首页
Swift 常用技术总结

Swift 常用技术总结

作者: 刘小弟 | 来源:发表于2017-03-29 20:41 被阅读97次

    特定导航栏隐藏

    override func viewDidLoad() {
         super.viewDidLoad()
         self.navigationController?.delegate = self
     }
    extension MLMineTableViewController:UINavigationControllerDelegate {
        func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool){
         let vcClass =  viewController.isKind(of:       
         MLMineTableViewController.superclass()!)
         self.navigationController?.navigationBar.isHidden = vcClass
         navigationController.setNavigationBarHidden(vcClass, animated: animated)
        }
    }
    

    ScrollView,TableView滑动键盘隐藏

    scrollView.keyboardDismissMode = .OnDrag
    or
    scrollView.keyboardDismissMode = .Interactive
    
    

    浮点数取整

    public func ceil(_: Double) -> Double  //取上整
    public func floor(_: Double) -> Double //取下整
    

    TableView的cell自适应高度,不用单独设置每个cell的高度

     self.tableView.rowHeight = UITableViewAutomaticDimension
     self.tableView.estimatedRowHeight = 200; //预计高度
    

    枚举类型

    @objc enum DrugStoreType: Int {
        case undefined = 0
        case online = 1
        case offlinee = 2
        var text: String {
            switch self {
            case .online:
                return "线上药店"
            case .offlinee:
                return "线下药店"
            default:
                return ""
            }
        }
    }
    let content = DrugStoreType.undefined.text  // 直接显示枚举对应的文本
    

    泛型

    任务:打印输出数组内所有的元素。

    var stringArray = ["苍老师", "范老师", "优衣库"]
    var intArray = [1, 3, 4, 5, 6]
    var doubleArray = [1.0, 2.0, 3.0]
    func printStringArray(a: [String]) {         
      for s in a {              
       print(s)        
       } }
    func printIntArray(a: [Int]) { 
      for i in a { 
        print(i) 
       } }
    func printDoubleArray(a: [Double]) {for d in a { print(d) } }
    

    简介版

    func printElementFromArray(a: [T]) {        
        for element in a {            
          print(element)        
         } }
    

    相关文章

      网友评论

          本文标题:Swift 常用技术总结

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