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

Text alignment is broken #68

Open
scalessec opened this issue Oct 27, 2015 · 5 comments
Open

Text alignment is broken #68

scalessec opened this issue Oct 27, 2015 · 5 comments

Comments

@scalessec
Copy link
Owner

As mention in #53, if the title or message is shorter than the width of the wrapper view, it does not appear to be centered.

@shidelinFYH
Copy link

I think a method just change UIView+Toast.m line 237 expectedSizeTitle = CGSizeMake(MAX(maxSizeTitle.width, expectedSizeTitle.width), MIN(maxSizeTitle.height, expectedSizeTitle.height)); but i don't know whether it has a bad effect, you can try it.

@ghost
Copy link

ghost commented Jul 12, 2016

Hi, has this been fixed? I've integrated toast using Pods, and title alignment does not seem to do anything. I've tried left, right and centre.

@funnel20
Copy link

funnel20 commented Jan 26, 2018

I have solved this issue in version 4.0.0 in:
- (UIView *)toastViewForMessage:(NSString *)message title:(NSString *)title image:(UIImage *)image style:(CSToastStyle *)style;

The details of the change are in PR #118.

Example

I used the Example project to test the changes for DEMO button Make toast with an image.
I modified the test code in tableView;didSelectRowAtIndexPath: to:

        // Customise the Toast via a style:
        CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle];
        style.titleAlignment = NSTextAlignmentCenter;
        style.messageAlignment = NSTextAlignmentLeft;
        style.horizontalPadding = 10;
        style.maxWidthPercentage = 0.82;
        
        // Make toast with a title
        [self.navigationController.view makeToast:@"This is a piece of toast with a title"
                                         duration:20.0
                                         position:CSToastPositionTop
                                            title:@"Toast Title"
                                            image:nil
                                            style:style
                                       completion:nil];

Current situation

When running this in 4.0.0, despite setting style.titleAlignment = NSTextAlignmentCenter the title is not centred, but left aligned:

original hor-padding-10 copy

Solution

After my code fix, the title is centred correctly:

fix hor-padding-10 copy

Bonus: this fixes more

My fix also solves a padding issue in version 4.0.0.
When changing style.horizontalPadding to 70 in the sample code from above, the wrapper clips over the display edges:

original hor-padding-70 copy

It definitely fails to comply to style.maxWidthPercentage. It should resize the title and message labels for the larger padding. Same sample code with my fix:

fix hor-padding-70 copy

Validation

Here are examples of other settings for style.titleAlignment and style.messageAlignment:

fix hor-padding-10-message_right copy

fix hor-padding-10-message_center copy

With an image, both title and message right aligned and padding set to 30:

fix image copy

funnel20 added a commit to funnel20/Toast that referenced this issue Jan 26, 2018
* The key it to use the same width for both UILabels. This will be the largest value of the 2 expected widths based on the text content.
* The available width for the UILabel was too large; the style.horizontalPadding wasn't respected.
@funnel20
Copy link

@scalessec Hi, any reaction would be appreciated.

bivant pushed a commit to bivant/Toast that referenced this issue Nov 28, 2018
* The key it to use the same width for both UILabels. This will be the largest value of the 2 expected widths based on the text content.
* The available width for the UILabel was too large; the style.horizontalPadding wasn't respected.
@funnel20
Copy link

funnel20 commented Sep 3, 2024

@scalessec Dear Charles, not only didn't you provide any reaction to my proposed solution or pull request, you also totally neglected my contribution when you updated your repo to version 4.1.x.
The bottom line is that this issue is still present in your code after 6 years, and other users are forced to create their own custom fork and keep that in line with your changes.

Can you tell me what would be required to get this resolution in an official release?

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

3 participants