Skip to content

Fix to properly show badge when use with UIView from .xib + layout in programmatically way#24

Open
haxpor wants to merge 2 commits intomustafaibrahim989:swift2from
haxpor:fix_layouting
Open

Fix to properly show badge when use with UIView from .xib + layout in programmatically way#24
haxpor wants to merge 2 commits intomustafaibrahim989:swift2from
haxpor:fix_layouting

Conversation

@haxpor
Copy link

@haxpor haxpor commented Apr 25, 2017

I found a problem of badge doesn't show when I have a button which is MIBadgeButton under a custom UIView from .xib, and when create an instance from that view, use programmatic way in creating constraints dynamically.

Thus this merge fixed this problem, and still respect the original way of positioning badge via modifying frame. It will check in view hierarchy first whether it needs to apply such solution or not.

The solution creates constraints dynamically to position badge properly and accordingly, and also use calculated values from original method too for performance.

Demo sample (also included in this merge) will be like this now
screen shot 2017-04-25 at 4 54 03 pm

The first row shows when use .xib and dynamic constraints.
The second row shows original and normal approach.

Edit:
This is against swift2. I can contribute for swift3 thus master branch later when this merge is accepted and merged.

haxpor added 2 commits April 25, 2017 16:26
constraint

- note that buttons in demo constructed to work with UIImageView.
  UIButton for logic, and UIImageView to represent button image i.e.
  facebook or twitter logo
- background color of CustomView and UIView that holds UIButton and
  UIImageView has transparent color thus badges from normal buttons
  can be properly showed

In short, it will work like before and no need to worry about different
usage. What added is taking care and handle for the case if user
construct UI element with .xib and in programmatically way with dynamic
constraint.

See the demo code for example.
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

Successfully merging this pull request may close these issues.

1 participant