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

Toast's title is not alignment center #53

Closed
tuanphamanh91 opened this issue Apr 8, 2015 · 8 comments
Closed

Toast's title is not alignment center #53

tuanphamanh91 opened this issue Apr 8, 2015 · 8 comments

Comments

@tuanphamanh91
Copy link

Hello, i work on iOS 8.1 and test on device.
Toast's title is not alignment center, please help me. Thanks advance!
Here is my code:

            [self.view makeToast:@"You've unlocked from level 16 to level 30!"
                        duration:4.0
                        position:CSToastPositionTop
                           title:@"Congratulations"];

Here is image:
Image of Yaktocat

@hidefguy
Copy link

Ditto - there should be a way to center-align the title; on short messages it's probably fine as is, on longer messages it looks ugly.

@chrisw59
Copy link

Please help me how i can add text center alignment. This is urgent issue for me.

@scalessec
Copy link
Owner

@adams0917 I'm finishing up a new version of Toast (3.0) that supports custom styling like this. If you want to try it now, here's the branch: https://github.com/scalessec/Toast/tree/experimental/3.0

Here's how you do it with Toast 3.0:

CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle];
style.titleAlignment = NSTextAlignmentCenter;

[self.view makeToast:@"This is a piece of toast."
            duration:3.0
            position:CSToastPositionBottom
               style:style];

If you want the title always be centered for all toast views you can just do this:

CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle];
style.titleAlignment = NSTextAlignmentCenter;

// set as the default style for all toast views going forward
[CSToastManager setSharedStyle:style];

Then you could just pass nil for the style parameter going forward and the title would always appear centered.

Please keep in mind though that the experimental/3.0 branch is still technically in development. I plan to have the official release out and available on CocoaPods by early next week. I'll close this issue once the release is officially out.

@chrisw59
Copy link

Thanks for your reply. But there is only 2.4 version i cocoapods. Is it support Center alignment (2.4 version)?

@scalessec
Copy link
Owner

No, you'll have to wait until next week if you want to use CocoaPods. You could hack 2.4 to support center alignment by changing line 303 in UIView+Toast.m to use NSTextAlignmentCenter... But that's probably not the best idea unless you create your own fork.

@scalessec
Copy link
Owner

3.0 is now available in CocoaPods. I have a few more updates that I'm going to release in 3.1 later this week.

@jhw8610
Copy link

jhw8610 commented Oct 27, 2015

Hey Charles, just a heads up, setting textAlignment to NSTextAlignmentCenter only sets the text alignment within the label frame. This means that if the title or message is shorter than the width of the wrapper view, it does not appear to be centered.

One way to fix this is to set 'UILabel'.center.x to wrapperView.center.x.

@scalessec
Copy link
Owner

@jhw8610, good catch. Sorry about that. I created a new issue (#68), and I'll include this fix in the next release (3.1) that I'm planning in the next few days. Let me know if you come up with any other issues related to style.

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

5 participants