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

Card align to top #643

Closed
maba1984 opened this issue Dec 21, 2016 · 8 comments
Closed

Card align to top #643

maba1984 opened this issue Dec 21, 2016 · 8 comments
Assignees

Comments

@maba1984
Copy link

Hi, i am not sure if this is a bug or if i did something wrong. Maybe you want to take a look at it...

http://stackoverflow.com/questions/41270762/how-to-position-top-in-ios-swift

@daniel-jonathan
Copy link
Member

daniel-jonathan commented Dec 21, 2016

I answered on StackOverflow :) It is not a bug, it is AutoLayout not used correctly.

@maba1984
Copy link
Author

i changed my code but still the same problem...

`import UIKit
import Material

class UserProfileViewController: UIViewController {
fileprivate var card: Card!

fileprivate var toolbar: Toolbar!
fileprivate var moreButton: IconButton!

fileprivate var contentView: UILabel!

fileprivate var bottomBar: Bar!
fileprivate var dateFormatter: DateFormatter!
fileprivate var dateLabel: UILabel!
fileprivate var favoriteButton: IconButton!


override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = UIColor(red:0.15, green:0.24, blue:0.37, alpha:1.0)
    guard let tc = toolbarController else {
        return
    }
    tc.toolbar.height = 0
    tc.toolbar.isHidden = true
    prepareDateFormatter()
    prepareDateLabel()
    prepareFavoriteButton()
    prepareMoreButton()
    prepareToolbar()
    prepareContentView()
    prepareBottomBar()
    prepareImageCard()
    prepareMainView()


}

}

extension UserProfileViewController {
fileprivate func prepareMainView() {
view.layout(card!).horizontally(left: 10, right: 10).top(10)
}

fileprivate func prepareDateFormatter() {
    dateFormatter = DateFormatter()
    dateFormatter.dateStyle = .medium
    dateFormatter.timeStyle = .none
}

fileprivate func prepareDateLabel() {
    dateLabel = UILabel()
    dateLabel.font = RobotoFont.regular(with: 12)
    dateLabel.textColor = Color.blueGrey.base
    dateLabel.text = dateFormatter.string(from: Date.distantFuture)
}

fileprivate func prepareFavoriteButton() {
    favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.red.base)
}

fileprivate func prepareMoreButton() {
    moreButton = IconButton(image: Icon.cm.moreVertical, tintColor: Color.blueGrey.base)
}

fileprivate func prepareToolbar() {
    toolbar = Toolbar(rightViews: [moreButton])
    
    toolbar.title = "Material"
    toolbar.titleLabel.textAlignment = .left
    
    toolbar.detail = "Build Beautiful Software"
    toolbar.detailLabel.textAlignment = .left
    toolbar.detailLabel.textColor = Color.blueGrey.base
}

fileprivate func prepareContentView() {
    contentView = UILabel()
    contentView.numberOfLines = 0
    contentView.text = "Material is an animation and graphics framework that is used to create beautiful applications."
    contentView.font = RobotoFont.regular(with: 14)
}

fileprivate func prepareBottomBar() {
    let clipboardButton = IconButton(image: UIImage(named: "clipboard_darken1.png"))
    let dashboardButton = IconButton(image: UIImage(named: "dashboard_darken1.png"))
    let bookmarkButton = IconButton(image: UIImage(named: "bookmark_darken1.png"))
    let dotsButton = IconButton(image: UIImage(named: "dots_darken1.png"))
    
    bottomBar = Bar()
    bottomBar.centerViews = [clipboardButton, dashboardButton, bookmarkButton, dotsButton]
}

fileprivate func prepareImageCard() {
    card = Card()
    
    card.toolbar = toolbar
    card.toolbarEdgeInsetsPreset = .square3
    card.toolbarEdgeInsets.bottom = 0
    card.toolbarEdgeInsets.right = 8
    
    card.contentView = contentView
    card.contentViewEdgeInsetsPreset = .wideRectangle3
    
    card.bottomBar = bottomBar
    card.bottomBarEdgeInsetsPreset = .wideRectangle2
}

}`

@daniel-jonathan
Copy link
Member

What version of Xcode are you using? This is interesting, I tested your code and the Sample project and I am seeing behavior I have not seen before.

@maba1984
Copy link
Author

I am using Version 8.2.1 of Xcode. I tried to add just the subviews "card.toolbar, card.contentView..." and that works fine. Just the hole card does not layout right.

@daniel-jonathan
Copy link
Member

The issue is that it is aligning from the center, not the top as would be expected. I am working on a fix now.

@maba1984
Copy link
Author

Thank you:)

@daniel-jonathan
Copy link
Member

Fixed it, now running tests and confirming I didn't create any issues :) This was a really good catch.

@daniel-jonathan
Copy link
Member

Please update to Material 2.4.3 and it should work perfectly with the suggestions I had made earlier. Thanks again, this was a really good catch.

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