2015-04-02 85 views
0

我在主視圖中添加Tabbarcontroller,但我沒有設置它的背景色...
我已經嘗試tabBar.barTintColor但它不工作..
添加的UIView如在的UITabBarController迅速

所以我想添加視圖作爲TabbarController(其中工作像UITabbar),但我沒有成功...
任何人都可以請幫助我。
下面是代碼

var tabBar = UITabBarController() 

    var frameOfView : CGRect = UIScreen.mainScreen().bounds 
    tabBar.view.frame = CGRectMake(frameOfView.origin.x, frameOfView.size.height, frameOfView.size.width, frameOfView.size.height-100) 

    var viewTabBar = UIView(frame: CGRectMake(frameOfView.origin.x, 430, frameOfView.size.width, 100)) 
    var BtnHomeTab = UIButton(frame: CGRectMake(0, 0, 30, 30)) 
    var imageHomeTab = UIImage(named: "home_selected.png") 
    viewTabBar.addSubview(BtnHomeTab) 

回答

0


要隱藏的UITabBarController .. :)

,然後將此代碼添加到您的appDelegate。

//MARK: CREATE BOTTOMBAR BUTTON 
func craeteBottonBarButton() 
{ 
    var viewBottom : UIView = UIView(frame: CGRectMake(0,window!.frame.size.height - 50.0,window!.frame.size.width,60.0)) 
    viewBottom.tag = TagWindow.Tag_Bottom.rawValue 
    window!.addSubview(viewBottom) 
    window!.bringSubviewToFront(viewBottom) 
    viewBottom.backgroundColor = GlobalConstants.GlobalConstants.ButtonConstant.BUTTONBACKGROUNDCOLOR 
    viewBottom.tag = TagWindow.Tag_Bottom.rawValue 

    var x : CGFloat = 0.0 
    for var i = 0 ; i < 5 ; i++ 
    { 
     var btn = createTabBarButton(viewBottom, 
      framebtn: CGRectMake(x,0, 65.0, 50.0), 
      tag: (i + 1), 
      imgName: arrayImage.objectAtIndex(i) as NSString , btnName: arrayLblName.objectAtIndex(i) as NSString) as UIButton 
     viewBottom.addSubview(btn) 
     x += 64.5 
    } 
} 


給所有導航控制器按鈕

func createTabBar() -> UITabBarController 
{ 
    var storyBoard = UIStoryboard(name: "Main", bundle: nil) 
    tabBar.delegate = self 
    var tabBarFont = UITabBar() 

    let HomeTab = storyBoard.instantiateViewControllerWithIdentifier("HomeVC") as HomeVC 
    let navigation_home = UINavigationController(rootViewController: HomeTab) 
    navigation_home.navigationBarHidden = true 

    let SearchTab = storyBoard.instantiateViewControllerWithIdentifier("SearchVC") as SearchVC 
    let navigation_search = UINavigationController(rootViewController: SearchTab) 
    navigation_search.navigationBarHidden = true 

    let SettingTab = storyBoard.instantiateViewControllerWithIdentifier("SettingVC") as SettingVC 
    let navigation_Setting = UINavigationController(rootViewController: SettingTab) 
    navigation_Setting.navigationBarHidden = true 

    let MySeatTab = storyBoard.instantiateViewControllerWithIdentifier("MySeatVC") as MySeatVC 
    let navigation_MySeat = UINavigationController(rootViewController: MySeatTab) 
    navigation_MySeat.navigationBarHidden = true