swift-第一天

作者: a6750108cb56 | 来源:发表于2017-04-06 10:47 被阅读11次

    一:如何创建pch文件

      swift中不能使用预编译文件,通常使用全局的常量来实现
    
      let kSCREEN_WIDTH  = UIScreen.main.bounds.size.width
      let kSCREEN_HEIGHT = UIScreen.main.bounds.size.height
    
      // RGBA的颜色设置
       func kRGBA (r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat) -> UIColor {
            return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a)
        }
    

    二:创建tabbar

        UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.gray], for: .normal)
        UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .selected)
        self.tabBar.tintColor = UIColor.orange
    

    三:引导界面的使用

        UserDefaults.standard.set(false, forKey: "firstLaunch")
        self.view.window?.rootViewController = self.storyboard?.instantiateViewController(withIdentifier: "HHHTabbarViewController")
        self.view.window?.addSubview((self.storyboard?.instantiateViewController(withIdentifier: "HHHTabbarViewController").view)!)
    

    四:在appdelegate中设置根目录

        if UserDefaults.standard.bool(forKey: "everLaunched") {
            UserDefaults.standard.set(true, forKey: "everLaunched")
            UserDefaults.standard.set(true, forKey: "firstLaunch")
        }
        
        let story = UIStoryboard.init(name: "Main", bundle: Bundle.main)
        if UserDefaults.standard.bool(forKey: "firstLaunch") {
            self.window?.rootViewController = story.instantiateViewController(withIdentifier: "HHHWelcomeViewController")
            self.window?.addSubview(story.instantiateViewController(withIdentifier: "HHHWelcomeViewController").view)
        }
        else {
            self.window?.rootViewController = story.instantiateViewController(withIdentifier: "HHHTabbarViewController")
            self.window?.addSubview(story.instantiateViewController(withIdentifier: "HHHTabbarViewController").view)
        }

    相关文章

      网友评论

        本文标题:swift-第一天

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