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

Help with Toolbar, leftViews too wide #618

Closed
theolof opened this issue Dec 1, 2016 · 7 comments
Closed

Help with Toolbar, leftViews too wide #618

theolof opened this issue Dec 1, 2016 · 7 comments
Assignees

Comments

@theolof
Copy link

theolof commented Dec 1, 2016

I'm not sure if this is an iOS thing or Material thing...
In your sample ToolbarController I'm trying to add an image instead of a button as the leftViews.

I've added this function

    fileprivate func prepareProfileImageView() {
        let profileImage = UIImage(named: "lys")?.resize(toWidth: 40)
        profileImageView = UIImageView(image: profileImage)
        profileImageView.layer.cornerRadius = profileImageView.image!.width / 2
        profileImageView.clipsToBounds = true
        profileImageView.contentMode = .scaleAspectFit
        profileImageView.backgroundColor = Color.red
   }

and replaced

    fileprivate func prepareToolbar() {
        toolbar.backgroundColor = Color.blue.darken2
        toolbar.leftViews = [menuButton]
        toolbar.rightViews = [starButton, searchButton]
    }

with

    fileprivate func prepareToolbar() {
        toolbar.backgroundColor = Color.blue.darken2
        toolbar.leftViews = [profileImageView]
        toolbar.rightViews = [starButton, searchButton]
    }

I'm expecting the image to be a circular image 40x40, but it's too wide. What am I doing wrong?

See attached image.
screen shot 2016-12-01 at 21 02 19

@daniel-jonathan
Copy link
Member

taking a look now :)

@daniel-jonathan
Copy link
Member

I got it working, and now only need to make sure there are not any regressions. I needed to make an update to Material. I will post an update very soon. I am aiming for tonight :)

@daniel-jonathan
Copy link
Member

daniel-jonathan commented Dec 4, 2016

I made some updates to Material, which will come out in an hour. Here is the code you can use, that was modified from the ToolbarController sample. Basically, you need a container view that is used for the Toolbar calculations, and then you can center an image within there :)

class AppToolbarController: ToolbarController {
    fileprivate var profileView: UIView!
    
    open override func prepare() {
        super.prepare()
        prepareProfileView()
        prepareStatusBar()
        prepareToolbar()
    }
}

extension AppToolbarController {
    fileprivate func prepareProfileView() {
        profileView = UIView()
        
        let imageView = View()
        imageView.shapePreset = .circle
        imageView.image = UIImage(named: "daniel")
        
        profileView.layout(imageView).width(30).height(30).center()
    }
    
    fileprivate func prepareStatusBar() {
        statusBarStyle = .lightContent
        statusBar.backgroundColor = Color.blue.darken3
    }
    
    fileprivate func prepareToolbar() {
        toolbar.interimSpacePreset = .interimSpace4
        toolbar.backgroundColor = Color.blue.darken2
        toolbar.leftViews = [profileView]
    }
}

screen shot 2016-12-04 at 1 05 46 pm

@theolof
Copy link
Author

theolof commented Dec 4, 2016

That looks great! Will test it tomorrow.

@daniel-jonathan
Copy link
Member

Please update to Material 2.4.0 for a solution to this issue :)

@theolof
Copy link
Author

theolof commented Dec 5, 2016

It Works™

@daniel-jonathan
Copy link
Member

wonderful :)

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

No branches or pull requests

2 participants