Swift学习记录 -- 16.微博项目初体验

23 篇文章 1 订阅

真正学习这门语言 , 也才两天 , 所以拿到小项目 , 虽然知道思路 , 却卡在语法上 .


// Appdelegateimport UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        //创建window
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        //设置根控制器
        window?.rootViewController = MYTabbarController()

        //设置为主窗口
        window?.makeKeyAndVisible()

        return true
    }
// MYNavigationController类

import UIKit

class MYNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()


    }
}

//进行全局设置
extension MYNavigationController {

    //重写initialize方法
    override class func initialize() {

        //设置全局颜色
        UITabBar.appearance().tintColor = UIColor.orangeColor()

    }
}
// MYTabbarController 类

import UIKit

class MYTabbarController: UITabBarController {


    override func viewDidLoad() {
        super.viewDidLoad()

        //初始化控制器:
        addChildControllers(HomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildControllers(MessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildControllers(DiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildControllers(MineViewController(), title: "我", imageName: "tabbar_profile")

    }
}


//添加子控制器
extension MYTabbarController {

    private func addChildControllers(childVc:UIViewController,title:String ,imageName:String) {

        childVc.title = title
        childVc.tabBarItem.image = UIImage(named: imageName)
        childVc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
        let navVc = MYNavigationController(rootViewController: childVc)
        addChildViewController(navVc)
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值