GithubHelp home page GithubHelp logo

Text alignment is broken about toast HOT 4 OPEN

scalessec avatar scalessec commented on August 23, 2024
Text alignment is broken

from toast.

Comments (4)

funnel20 avatar funnel20 commented on August 23, 2024 4

@scalessec Hi, any reaction would be appreciated.

from toast.

funnel20 avatar funnel20 commented on August 23, 2024 1

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

from toast.

shidelinFYH avatar shidelinFYH commented on August 23, 2024

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.

from toast.

 avatar commented on August 23, 2024

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.

from toast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.