         super.init(frame: frame)
     }
     
-    override public func drawRect(rect: CGRect) {
+    override public func layoutSubviews() {
+        super.layoutSubviews()
+        
         // set custom attrs
         tabSectionScrollView.backgroundColor = tabSectionBackgroundColor
         contentSectionScrollView.backgroundColor = contentSectionBackgroundColor

        // first time setup pages
        setupPages()
        
        // first time
        if (!isStarted) {
            // set defaule pageIndex
            pageIndex = defaultPage
            
            isStarted = true
        }
        
        // load pages

            if (numberOfPages != 0) {
                var tabOffsetX = 0 as CGFloat
                var contentOffsetX = 0 as CGFloat
                for _ in 0 ..< index {
                    tabOffsetX += widthForTabAtIndex(index)
                    contentOffsetX += self.frame.width
                }
                dispatch_async(dispatch_get_main_queue()) {
                    // set default position of tabs and contents
                    self.tabSectionScrollView.contentOffset = CGPoint(x: tabOffsetX + self.tabSectionScrollView.contentInset.left * -1, y: self.tabSectionScrollView.contentOffset.y)
                    self.contentSectionScrollView.contentOffset = CGPoint(x: contentOffsetX  + self.contentSectionScrollView.contentInset.left * -1, y: self.contentSectionScrollView.contentOffset.y)
                    print(self.contentSectionScrollView.contentOffset)
                    self.updateTabAppearance()
                }
            }
            prevPageIndex = index
        }
