subinspathilettu / SJSegmentedViewController

MIT License
334 stars 126 forks source link

Custom view for all tabs view #42

Closed stasberkman closed 7 years ago

stasberkman commented 7 years ago

Hi

I want to make the background color of the tabs view to be gradient, how can i set one custom view for all the tabs

Thanks

SonnetXavier commented 7 years ago

Hi @stasberkman ,

You can create a xib file with the custom view (with background view and label) as required. And set this custom view as the navigationItem.titleView for each of the View Controllers.

Code snippet follows:

let firstViewController = storyboard
                .instantiateViewController(withIdentifier: "FirstViewController")
            firstViewController.title = "FIRST"

 let view = UIView()
 view.layer.masksToBounds = true
 view.contentMode = .scaleAspectFit
if let customView = Bundle.main.loadNibNamed("TabCustomView", owner: self, options: nil)?.first as? TabCustomView {

                customView.frame = CGRect(x: 0, y: 0, width: 30, height: 5   )
                customView.layer.masksToBounds = true
                customView.contentMode = .scaleAspectFit
                 view.addSubview(customView)
 firstViewController.navigationItem.titleView = view
}
let segmentController = SJSegmentedViewController()
segmentController.segmentControllers = [firstViewController, secondViewController]

Hope this helps!

stasberkman commented 7 years ago

Yes but if i want a gradient background color for the all segment view, i don't have a control of that.

for example this behaivour:

screen shot 2017-02-13 at 8 33 28
SonnetXavier commented 7 years ago

Currently, we don't have a direct way to work this out, We will try to include this in a new update.