美文网首页
重定义UITabBar

重定义UITabBar

作者: 潜水100号 | 来源:发表于2016-09-18 22:14 被阅读0次
    Snip20160918_1.png

    swift

    主界面

    class ViewController: UITabBarController {
    
      override func viewDidLoad() {
        super.viewDidLoad()
       
        var vcCtl1 = UIViewController()
        vcCtl1.view.backgroundColor = UIColor.redColor()
        vcCtl1.tabBarItem.title = "first"
       
        var vcCtl2 = UIViewController()
        vcCtl2.view.backgroundColor = UIColor.blueColor()
        vcCtl2.tabBarItem.title = "second"
       
        var vcCtl3 = UIViewController()
        vcCtl3.view.backgroundColor = UIColor.greenColor()
        vcCtl3.tabBarItem.title = "third"
       
        self.viewControllers = [vcCtl1,vcCtl2,vcCtl3]
       
        creatrUItabar()
      }
     
      func creatrUItabar(){
        var b = bar(frame: self.tabBar.bounds)
        //用新的将原来的tabBar覆盖掉
        self.setValue(b, forKey: "tabBar")
      }
    

    重定义UITabBar

    class bar: UITabBar {
     
      override init(frame: CGRect) {
        super.init(frame: frame)
        self.barTintColor = UIColor.blackColor()
        createUI()
       
      }
     
      func createUI(){
        for i in 1...2{
          //确定了大小上下
          var image = UIImageView(frame: CGRectMake(0, 5, 2, 40))
          image.image = UIImage(named: "1")
          //确定位置
          image.center = CGPointMake(((UIScreen.mainScreen().bounds.size.width)/3)*CGFloat(i), image.center.y)
          self.addSubview(image)
        }
       
    
      }
     
      required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
      }
    }
    

    相关文章

      网友评论

          本文标题:重定义UITabBar

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