<commit_before>//
//  KZSegmentedPageView.swift
//  Practice
//
//  Created by <NAME> on 04/12/2016.
//
//

import UIKit

@IBDesignable public class KZSegmentedPageView: UIView {
    public weak var delegate:KZSegmentedPageViewDelegate?
    
    private var view:UIView!
    private var pageViewControllerView: UIView!
    var segmentedControl: UISegmentedControl!
    public var pageViewController:UIPageViewController!
    
    var segmentedHeighConstraint: NSLayoutConstraint!
    var segmentedTopPaddingConstraint: NSLayoutConstraint!
    var segmentedLeftPaddingConstraint: NSLayoutConstraint!
    var segmentedRightPaddingConstraint: NSLayoutConstraint!
    var segmentedBottomPaddingToPageViewControllerConstraint: NSLayoutConstraint!
    
    public func configure(owner:UIViewController, segments:[KZSegment]) {
        owner.addChildViewController(pageViewController)
        self.segments = segments
    }
    
    
    @IBInspectable public var scHeight:CGFloat = 29 {
        didSet {
            segmentedHeighConstraint.constant = scHeight
            view.layoutIfNeeded()
        }
    }
    
    @IBInspectable public var scPaddingLeft:CGFloat = 8 {
        didSet {
            segmentedLeftPaddingConstraint.constant = scPaddingLeft
            view.layoutIfNeeded()
        }
    }
    
    @IBInspectable public var scPaddingRight:CGFloat = 8 {
        didSet {
            segmentedRightPaddingConstraint.constant = scPaddingRight
            view.layoutIfNeeded()
        }
    }
    
    @IBInspectable public var scPaddingTop:CGFloat = 8 {
        didSet {
            segmentedTopPaddingConstraint.constant = scPaddingTop
            view.layoutIfNeeded()
        }
    }
    
    @IBInspectable public var scPaddingBottom:CGFloat = 8 {
        didSet {
            segmentedBottomPaddingToPageViewControllerConstraint.constant = scPaddingBottom
            view.layoutIfNeeded()
        }
    }
    
    @IBInspectable public var scTintColor:UIColor = UIColor(colorLiteralRed: 0, green: 122/255, blue: 1, alpha: 1) {
        didSet {
            segmentedControl.tintColor = scTintColor
        }
    }
    
    @IBInspectable public var scBackgroundColor:UIColor = UIColor.clearColor() {
        didSet {
            segmentedControl.backgroundColor = scBackgroundColor
            segmentedControl.clipsToBounds = true
            segmentedControl.layer.cornerRadius = 4
        }
    }
    
    @IBInspectable public var viewBackgroundColor:UIColor = UIColor.whiteColor() {
        didSet {
            view.backgroundColor = viewBackgroundColor
        }
    }
    
    
   
    
    
    
    @IBAction func segmentedControlClicked(sender: UISegmentedControl) {
        delegate?.segmentedPageView(self, didSelectSegmentAtIndex: sender.selectedSegmentIndex)
        scrollToViewController(index: sender.selectedSegmentIndex)
    }
    
    private var transitionInProgress:Bool = false
    public var isTransitioning:Bool {
        return transitionInProgress
    }
    
    public var segments:[KZSegment] = [] {
        didSet {
            pageViewController.dataSource = self
            pageViewController.delegate = self
            
            if let initialViewController = segments.first?.viewController {
                scrollToViewController(initialViewController, direction: .Forward)
            }
            delegate?.segmentedPageView(self, didUpdatePageCount: segments.count)
            
            segmentedControl.removeAllSegments()
            for i in 0..<segments.count {
                segmentedControl.insertSegmentWithTitle(segments[i].title, atIndex: i, animated: false)
            }
            
            segmentedControl.selectedSegmentIndex = 0
        }
    }
    
    func xibSetup() {
        view = loadViewFromNib()
        
        
        pageViewController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
        pageViewController.view.frame = pageViewControllerView.bounds
        pageViewControllerView.addSubview(pageViewController.view)
        
//        pageViewController.view.bindFrameToSuperviewBounds()
        
        pageViewControllerView.layoutIfNeeded()
    }
    
    func loadViewFromNib() -> UIView {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 375, height: 667))
//        view.frame = bounds
        view.backgroundColor = UIColor.whiteColor()
        view.translatesAutoresizingMaskIntoConstraints = false
        addSubview(view)
        
        pageViewControllerView = UIView(frame: CGRect(x: 0, y: 44, width: 375, height: 623))
        pageViewControllerView.backgroundColor = UIColor.grayColor()
        pageViewControllerView.translatesAutoresizingMaskIntoConstraints = false
        
        segmentedControl = UISegmentedControl(frame: CGRect(x: 8, y: 8, width: 359, height: 29))
        segmentedControl.insertSegmentWithTitle("Segment 1", atIndex: 0, animated: false)
        segmentedControl.insertSegmentWithTitle("Segment 2", atIndex: 1, animated: false)
        segmentedControl.translatesAutoresizingMaskIntoConstraints = false
        segmentedControl.selectedSegmentIndex = 0<commit_msg>added more functions and variables to public scopes<commit_after>//
//  KZSegmentedPageView.swift
//  Practice
//
//  Created by <NAME> on 04/12/2016.
//
//

import UIKit

public class KZSegmentedPageView: UIView {
    public weak var delegate:KZSegmentedPageViewDelegate?
    
    private var view:UIView!
    private var pageViewControllerView: UIView!
    public var segmentedControl: UISegmentedControl!
    public var pageViewController:UIPageViewController!
    
    var segmentedHeighConstraint: NSLayoutConstraint!
    var segmentedTopPaddingConstraint: NSLayoutConstraint!
    var segmentedLeftPaddingConstraint: NSLayoutConstraint!
    var segmentedRightPaddingConstraint: NSLayoutConstraint!
    var segmentedBottomPaddingToPageViewControllerConstraint: NSLayoutConstraint!
    
    public func configure(owner:UIViewController, segments:[KZSegment]) {
        owner.addChildViewController(pageViewController)
        self.segments = segments
    }
    
    @IBInspectable public var scHeight:CGFloat = 29 {
        didSet {
            segmentedHeighConstraint.constant = scHeight
            view.layoutIfNeeded()
        }
    }
    
    @IBInspectable public var scPaddingLeft:CGFloat = 8 {
        didSet {
            segmentedLeftPaddingConstraint.constant = scPaddingLeft
            view.layoutIfNeeded()
        }
    }
    
    @IBInspectable public var scPaddingRight:CGFloat = 8 {
        didSet {
            segmentedRightPaddingConstraint.constant = scPaddingRight
            view.layoutIfNeeded()
        }
    }
    
    @IBInspectable public var scPaddingTop:CGFloat = 8 {
        didSet {
            segmentedTopPaddingConstraint.constant = scPaddingTop
            view.layoutIfNeeded()
        }
    }
    
    @IBInspectable public var scPaddingBottom:CGFloat = 8 {
        didSet {
            segmentedBottomPaddingToPageViewControllerConstraint.constant = scPaddingBottom
            view.layoutIfNeeded()
        }
    }
    
    @IBInspectable public var scTintColor:UIColor = UIColor(colorLiteralRed: 0, green: 122/255, blue: 1, alpha: 1) {
        didSet {
            segmentedControl.tintColor = scTintColor
        }
    }
    
    @IBInspectable public var scBackgroundColor:UIColor = UIColor.clearColor() {
        didSet {
            segmentedControl.backgroundColor = scBackgroundColor
            segmentedControl.clipsToBounds = true
            segmentedControl.layer.cornerRadius = 4
        }
    }
    
    @IBInspectable public var viewBackgroundColor:UIColor = UIColor.whiteColor() {
        didSet {
            view.backgroundColor = viewBackgroundColor
        }
    }
    
    
    @IBAction func segmentedControlClicked(sender: UISegmentedControl) {
        delegate?.segmentedPageView(self, didSelectSegmentAtIndex: sender.selectedSegmentIndex)
        scrollToViewController(index: sender.selectedSegmentIndex)
    }
    
    private var transitionInProgress:Bool = false
    public var isTransitioning:Bool {
        return transitionInProgress
    }
    
    public var segments:[KZSegment] = [] {
        didSet {
            pageViewController.dataSource = self
            pageViewController.delegate = self
            
            if let initialViewController = segments.first?.viewController {
                scrollToViewController(initialViewController, direction: .Forward)
            }
            delegate?.segmentedPageView(self, didUpdatePageCount: segments.count)
            
            segmentedControl.removeAllSegments()
            for i in 0..<segments.count {
                segmentedControl.insertSegmentWithTitle(segments[i].title, atIndex: i, animated: false)
            }
            
            segmentedControl.selectedSegmentIndex = 0
        }
    }
    
    func xibSetup() {
        view = loadViewFromNib()
        
        
        pageViewController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
        pageViewController.view.frame = pageViewControllerView.bounds
        pageViewControllerView.addSubview(pageViewController.view)
        
//        pageViewController.view.bindFrameToSuperviewBounds()
        
        pageViewControllerView.layoutIfNeeded()
    }
    
    func loadViewFromNib() -> UIView {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 375, height: 667))
//        view.frame = bounds
        view.backgroundColor = UIColor.clearColor()
        view.translatesAutoresizingMaskIntoConstraints = false
        addSubview(view)
        
        pageViewControllerView = UIView(frame: CGRect(x: 0, y: 44, width: 375, height: 623))
        pageViewControllerView.backgroundColor = UIColor.clearColor()
        pageViewControllerView.translatesAutoresizingMaskIntoConstraints = false
        
        segmentedControl = UISegmentedControl(frame: CGRect(x: 8, y: 8, width: 359, height: 29))
        segmentedControl.insertSegmentWithTitle("Segment 1", atIndex: 0, animated: false)
        segmentedControl.insertSegmentWithTitle("Segment 2", atIndex: 1, animated: false)
        segmentedControl.translatesAutoresizingMaskIntoConstraints = false
        segmentedControl.selectedSegmentIndex = 0
{'fraction_non_alphanumeric': 0.0699942073759413, 'fraction_numerical': 0.01061981077428075, 'mean_word_length': 2.5893970893970892, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4431571', 'n_tokens_mistral': 2848, 'n_tokens_neox': 2675, 'n_words': 524}