ealeksandrov/EAIntroView

Improve Skip Button customization

Ying1986 opened this issue · 7 comments

How can I change the height of skip button?

I placed page control to vertical center.

Pass you custom button with desired frame:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(0, 0, 230, 40)];
[btn setTitle:@"SKIP NOW" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btn.layer.borderWidth = 2.f;
btn.layer.cornerRadius = 10;
btn.layer.borderColor = [[UIColor whiteColor] CGColor];
intro.skipButton = btn;
intro.skipButtonY = 60.f;
intro.skipButtonAlignment = EAViewAlignmentCenter;

@ealeksandrov

This library is use AutoLayout inner code, so button height changed fit heigh.

So I think you have to add skipbutton height property and add constraint height if user set it,

Can you create skip button with height 100 with your code?

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(0, 0, 230, 40)];
[btn setTitle:@"SKIP NOW" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btn.layer.borderWidth = 2.f;
btn.layer.cornerRadius = 10;
btn.layer.borderColor = [[UIColor whiteColor] CGColor];
intro.skipButton = btn;
intro.skipButtonY = 60.f;
intro.skipButtonAlignment = EAViewAlignmentCenter;

Sounds legit. I'll check this.

Confirmed, will make a note for improving customization in next releases.

Any update to set height of button ?

When customize 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.

There is a workaround. Create blank UIImage of a size that you want you button be and set is as a background.

let skipButton = UIButton(type: .custom)
skipButton.frame = CGRect(x: 0, y: parentView.bounds.size.height - 50, width: parentView.bounds.size.width, height: 50)
let blankImage = UIImage.emptyImage(with: skipButton.frame.size)
skipButton.setBackgroundImage(blankImage, for: .normal)
skipButton.setTitle("Пропустить", for: .normal)
skipButton.backgroundColor = .charcoalGrey
skipButton.setTitleColor(.white, for: .normal)
skipButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
intro.skipButton = skipButton;
intro.skipButtonY = 50;
intro.skipButtonAlignment = .center

Use this extension to create a blank image:

extension UIImage {
    
    static func emptyImage(with size: CGSize) -> UIImage? {
        UIGraphicsBeginImageContext(size)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }
    
}