美文网首页
swift3.0 自己用模板

swift3.0 自己用模板

作者: 0o简单o0 | 来源:发表于2017-10-31 11:19 被阅读0次

    swift3.0 自己用模板(备用)

    tableview模板
    //
    //  ___FILENAME___
    //  ___PROJECTNAME___
    //
    //  Created by ___FULLUSERNAME___ on ___DATE___.
    //___COPYRIGHT___
    //
    
    import UIKit
    
    class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___,UITableViewDelegate,UITableViewDataSource {
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            //自动适应高度
            self.tableView.estimatedRowHeight = <#80#>
            self.tableView.rowHeight = UITableViewAutomaticDimension
        }
        
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            
        }
        
        //MARK:- --------tableView------
        func numberOfSections(in tableView: UITableView) -> Int {
            return <#1#>
        }
        
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return <#1#>
        }
        
        func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return <#44#>
            
        }
        /***tableView头部***/
        func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
            return <#44#>
        }
        
        func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
            let headerView = UIView.init(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: <#44#>))
            headerView.backgroundColor = UIColor.white
            
            
            return headerView
        }
        /***TableViewCell***/
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            
            var nibname = ""
            var cellID = ""
            
            nibname = ""
            cellID = ""
            
            var nibregistered = false
            if !nibregistered {
                let nib = UINib(nibName: nibname, bundle: nil)
                tableView.register(nib, forCellReuseIdentifier: cellID)
                nibregistered = true
            }
            let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath) as! <#TableViewCell Name#>
            
            cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator//右边图标
            cell.selectionStyle = UITableViewCellSelectionStyle.none//点击效果
            cell.setNeedsUpdateConstraints()
            cell.updateConstraintsIfNeeded()
            return cell
        }
        
        func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            
        }
        
    }
    
    CollectionView模板
    //
    //  ___FILENAME___
    //  ___PROJECTNAME___
    //
    //  Created by ___FULLUSERNAME___ on ___DATE___.
    //___COPYRIGHT___
    //
    
    import UIKit
    
    
    class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
        
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            
        }
    
        //MARK:- -----UICollectionViewDelegate-----
        func numberOfSections(in collectionView: UICollectionView) -> Int {
            
            return 0
        }
        
        func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            
            return 0
        }
        
        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            
            let nibname = ""
            let cellID = ""
            var nibregistered = false
            if !nibregistered {
                let nib = UINib(nibName: nibname, bundle: nil)
                collectionView.register(nib, forCellWithReuseIdentifier: cellID)
                nibregistered = true
            }
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellID, for: indexPath)
            
            
            
            return cell
        }
        
        func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
            
            
        }
        
        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
            
            return CGSize(width: 40, height: 39)
            
        }
    
    }
    
    

    相关文章

      网友评论

          本文标题:swift3.0 自己用模板

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