Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PagerController Embedded with SearchBar at the top causing issues #32

Open
Smiller193 opened this issue Jun 2, 2018 · 1 comment
Open

Comments

@Smiller193
Copy link

For some reason when I try to add a searchBar at the top of the pager controller it comes looking all messed up. im not sure if it is not customizable to that extent or what but it usually ends up looking like this
screen shot 2018-06-02 at 9 18 32 am

Where the screen is black which makes zero sense because i set the background to white and it overlaps the searchbar.

import UIKit
import DTPagerController

class NewSearchViewController: DTPagerController, UISearchBarDelegate {
    let dividerView = UIView()

    lazy var searchBar: UISearchBar = {
        let sb = UISearchBar()
        sb.placeholder = "Search"
        sb.searchBarStyle = .minimal
        sb.sizeToFit()
        sb.setScopeBarButtonTitleTextAttributes([ NSAttributedStringKey.foregroundColor.rawValue : UIColor.black], for: .normal)
        let textFieldInsideUISearchBar = sb.value(forKey: "searchField") as? UITextField
        textFieldInsideUISearchBar?.font = UIFont.systemFont(ofSize: 14)
        sb.layer.borderColor = UIColor.lightGray.cgColor
        sb.layer.borderWidth = 0.3
        sb.layer.cornerRadius = 5
        sb.layer.masksToBounds = true
        sb.showsCancelButton = true
        sb.barTintColor = UIColor.white
        sb.tintColor = UIColor.rgb(red: 24, green: 136, blue: 211)
        UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = UIColor.rgb(red: 230, green: 230, blue: 230)
        sb.delegate = self
        return sb
    }()
    
    init() {
        super.init(viewControllers: [])
        title = "View Controller"
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        addVC()
        setupVC()
    }
    @objc func addVC(){
        let viewController1 = EventSearchCollectionView(collectionViewLayout:  UICollectionViewFlowLayout())
        let viewController2 = UserSearchCollectionView(collectionViewLayout:  UICollectionViewFlowLayout())
                viewController1.title = "Events"
                viewController2.title = "Users"
                selectedFont =  UIFont(name: "Avenir-Medium", size: 14)!
                selectedTextColor = UIColor.black
                preferredSegmentedControlHeight = 40
                perferredScrollIndicatorHeight = 1.8
                scrollIndicator.backgroundColor = UIColor.black
                viewControllers = [viewController1, viewController2]
    }

    @objc func setupVC(){
        view.addSubview(searchBar)
        view.addSubview(dividerView)
        searchBar.snp.makeConstraints { (make) in
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
            make.left.right.equalTo(view)
        }
        UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes([NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue): UIColor.lightGray], for: .normal)

        dividerView.backgroundColor = .lightGray
        dividerView.snp.makeConstraints { (make) in
            make.left.right.equalTo(view)
            make.height.equalTo(0.5)
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

i have included the code above if that helps

@SerxhioGugo
Copy link

instead of using a search bar you should use a SearchController which will always be the view on the top, than when you use DTPager, your view will show just fine

IMG_4985

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants