swift-实例🌰

swift-第一天

2017-04-06  本文已影响11人  a6750108cb56

一:如何创建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)
    }
上一篇下一篇

猜你喜欢

热点阅读