ranesr/SwiftIcons

UIBarButtonItem is not aligned

yeralin opened this issue · 5 comments

Hi, I'm using SwiftIcons library (installed though Pod).

I'm trying to create UIBarButtonItem with specific icon.
I set it like this:
menuButton.setIcon(icon: .ionicons(.navicon), iconSize: 35, color: systemColor)
where systemColor == UIView().tintColor
But with this setup, my UIBar looks like this:
image
As, you can see it is not aligned vertically (I tried using SetTitlePositionAdjustment, but I can adjust only horizontal position).

I kinda fixed the position by using:
menuButton.setIcon(prefixText: "", icon: .ionicons(.navicon), iconColor: systemColor, postfixText: "", cgRect: CGRect(x: 30, y: 30, width: 30, height: 30), size: 35, iconSize: 36)
image

But, then button is not tappable...

Can anyone help me here?

Please Check Release 1.5.

I have added Example 3 (Icon with custom cgRect) in README.

@ranesr thank you :) I was already trying to fix myself. You were faster :D

We gotta little problem here.
Since it is a custom button, with your new change, fading effect on button press is gone now.
I was able to fix it by modifying function like this:

public func setIcon(icon: FontType, iconSize: CGFloat, color: UIColor = .black, cgRect: CGRect, target: AnyObject?, action: Selector) {
        title = nil
        let button = UIButton(frame: cgRect)
        let onPressColor = color.withAlphaComponent(0.4)
        button.setIcon(icon: icon, iconSize: iconSize, color: color, forState: .normal)
        button.addTarget(target, action: action, for: .touchUpInside)
        button.setTitleColor(onPressColor, for: .highlighted)
        customView = button
    }

If you approve, I will create a PR