Swiftmessages: [Small new feature] Need support for iPad to restrict toast width

Created on 17 Jul 2017  路  8Comments  路  Source: SwiftKickMobile/SwiftMessages

I really loved this library. I have one trouble when running in iPad. It works great, but it takes full width of the context to show the toast. Is it possible to add a new variable to set the preferred maximum width of toast?

Thanks

All 8 comments

I figured out that I can create nib file for that, so I am closing it. Thanks

That will work. Message views always span the full width, so you'll need to set backgroundView to a subview and set the width of backgroundView. The CardView and TabView layouts are configured this way. If you're using either of these, you can avoid the custom nib by using one of these APIs:

view.configureBackgroundView(width:) view.configureBackgroundView(sideMargin:)

@wtmoose, Great. I am using CardView, than I can use this methods to configure width. Thank you for the help. This is really super cool library and well architectured.

Wouldn't it make more sense to default to non-full-width messages on iPads? I mean, it really looks like not well thought through from the users perspective when the defaults are used and the defaults should be useful for most cases, no customization should be needed and it should look fine already. Having it full-width on iPad basically means this library doesn't _really_ support iPads but rather iPhones only ... even the Demo isn't iPad-compatible which is a sign I'm right.

So, what do you think, can we reopen this? If you're interested, I could add more native iPad support for both the library and the demo project.

Hi, I am using SwiftMessagesSegue, and I really need to use some static width. I checked inside the class but I could not find any helpful method because of messageView is not class of "MessageView".

So, I could not use below function.

view.configureBackgroundView(width:)
view.configureBackgroundView(sideMargin:)

public var messageView: SwiftMessages.BaseView
public var containerView: SwiftMessages.ViewControllerContainerView

There are plenty of variable inside BaseView, like backgroundHeight, or layout margin although it would be great if you support width variable too.

@rajaths131 I know you found a workaround for this, but that's IMHO not a reason to close it, especially given that for others (like me) this issue is still apparent. So could you try reopening this? I'm not sure if GitHub allows that, but it allowed you to close it, so it might work ... ?

@goktugaral I'll take a look at pushing those methods up the parent class. However, you should be able to do:

swift segue.messageView.backgroundView.widthAnchor.constraint(equalToConstant: 100).isActive = true

As the doc states, this method is only intended to be shortcut adding a width constraint. You're free to add Auto Layout constraints directly.

swift /** A shortcut for adding a width constraint to the `backgroundView`. When calling this method, it is important to ensure that the width constraint doesn't conflict with other constraints. The CardView.nib and TabView.nib layouts are compatible with this method. */ public func configureBackgroundView(width: CGFloat) { let constraint = NSLayoutConstraint(item: backgroundView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: width) backgroundView.addConstraint(constraint) }

Closing. iPad no longer defaults to full width on iPad.

Was this page helpful?
0 / 5 - 0 ratings