CRey
CRey

Reputation: 1160

How do you auto layout constraint a notification label inside a button?

This is the screenshot of my issue.

enter image description here

My problem is the button label is not a view. I can not anchor that notification label to it. If I anchor that label to any of the sides, the screen size will affect it.

Example: 6s Plus

enter image description here

and iPhone SE

enter image description here

It's fine on the bigger phones.

Upvotes: 0

Views: 163

Answers (2)

CRey
CRey

Reputation: 1160

I think the best way is to make a UIView with the badge and the title label in it and just overlay a UIButton with no title. This way you can constraint the badge label and the title label together.

Upvotes: 0

cookednick
cookednick

Reputation: 1088

BhargavR has the right idea. Subclass UIButton and add the badge as a subview constrained to the button's textLabel (the UILabel it uses) property.

Upvotes: 1

Related Questions