subinspathilettu / SJSegmentedViewController

MIT License
334 stars 126 forks source link

How i set the image on the segmented tab bar instead of title? #22

Closed HariNarayanan777 closed 7 years ago

HariNarayanan777 commented 7 years ago

I try to set image on tab bar, but it won't come

Its come like this simulator screen shot 16 nov 2016 13 28 25

I tried this code in the below function firstViewController.tabBarItem.image = UIImage(named: "1-1.png")

func getSJSegmentedViewController() -> SJSegmentedViewController? {

    if let storyboard = self.storyboard {

        let headerViewController = storyboard
            .instantiateViewController(withIdentifier: "HeaderViewController1")

        let firstViewController = storyboard
            .instantiateViewController(withIdentifier: "FirstTableViewController")
        //firstViewController.title = "Table View"
        **firstViewController.tabBarItem.image = UIImage(named: "1-1.png")**
subinspathilettu commented 7 years ago

@HariNarayanan777 Currently we didn't add image support for segment tab. We will add this feature in next release and let you know.

subinspathilettu commented 7 years ago

@HariNarayanan777 ,

We have added custom view support for segment tab in the latest version. For that, you need to provide your view for controller.navigationItem.titleView

// Custom ImageView
let view = UIImageView()
view.frame.size.width = 100
view.image = UIImage(named: imageName)
view.contentMode = .scaleAspectFit
view.backgroundColor = .white

firstViewController.navigationItem.titleView = view
HariNarayanan777 commented 7 years ago

@subinspathilettu super its working.......