ealeksandrov / EAIntroView

Highly customizable drop-in solution for introduction views.
MIT License
3.76k stars 501 forks source link

Could not rounded the skip button correctly when customizing the Skip Button #216

Closed Ververtom closed 6 years ago

Ververtom commented 6 years ago

When customizing the skip button, the height is more than 40dp, and I set btn.layer.cornerRadius equals 20, and masks to bouds yes, but the btn was not rounded correctly.

ealeksandrov commented 6 years ago

height is more than 40dp

what is "dp"?

was not rounded correctly

what do you mean? anything happens or something wrong happens?

Ververtom commented 6 years ago

@ealeksandrov OK, I will show my code.

   EAIntroView *intro = [[EAIntroView alloc] initWithFrame:self.window.rootViewController.view.bounds andPages:@[page1,page2,page3]];
    intro.pageControlY = 60.f;
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 295, 66);
    [btn setTitle:@"开始体验" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor colorWithTextName:@"red_500" alpha:0.7]];
    btn.layer.cornerRadius = 66/2.0;
    btn.layer.masksToBounds = YES;
    intro.skipButton = btn;
    intro.skipButtonY = 180.f;
    intro.skipButtonAlignment = EAViewAlignmentCenter;

The skip button should be like round but actually it was not. It like this shape: < >. image

And the height of the skip button is only 40, here is the frame and bounds showed by the debug view hierarchy. image

ghost commented 6 years ago

++ 1

ealeksandrov commented 6 years ago

write it by myself

instead of fixing issue and writing PR you want to rewrite everything from scratch?

I'm not paid tech support, will look into it when I have free time after work. No deadlines ever promised.

ealeksandrov commented 6 years ago

Intro view frame laid out with auto layout and it respects its intrinsic size if no additional constraints are added. Setting button's frame is useless.

Add width and height constraints:

[intro addConstraint:[NSLayoutConstraint constraintWithItem: btn
                                                  attribute: NSLayoutAttributeWidth
                                                  relatedBy: NSLayoutRelationEqual
                                                     toItem: nil
                                                  attribute: NSLayoutAttributeNotAnAttribute
                                                 multiplier: 1.0
                                                   constant: 295]];
[intro addConstraint:[NSLayoutConstraint constraintWithItem: btn
                                                  attribute: NSLayoutAttributeHeight
                                                  relatedBy: NSLayoutRelationEqual
                                                     toItem: nil
                                                  attribute: NSLayoutAttributeNotAnAttribute
                                                 multiplier: 1.0
                                                   constant: 66]];
screen shot 2017-12-19 at 20 25 50
Ververtom commented 6 years ago

@ealeksandrov Thx, I just customized the Button which was based on your pods, but then you gave a better way to fix my problem, so I think what I put up should not be a problem, it supports .