TOMSMorphingLabel icon indicating copy to clipboard operation
TOMSMorphingLabel copied to clipboard

UIButton & TOMSMorphingLabel

Open vicc opened this issue 10 years ago • 5 comments

I would love to see UIButton's label support the morphing effect! Great job btw!

vicc avatar Dec 12 '14 08:12 vicc

+1

tried some quick hacking here but with no good results =/

cytryn avatar Feb 06 '15 20:02 cytryn

@TomKnig @cytryn Hadn't actually given this a try until now, but it's a fairly simple solution. At first glance your gut may be telling you to simply set your UIButton's titleLabel to your TOMSMorphingLabel, but as it so happens, a UIButton's titleLabel is readonly. However, by simply adding TOMSMorphingLabel as a subview of our UIButton, everything can still work beautifully. Don't add it as a subview of your UIButton's titleLabel though. How come? Well, when titleLabel.text is nil, it's frame is pretty much {{0, 0}, {0, 0}}, meaning your animatedLabel will randomly appear to disappear (or never show up since you'll probably always set the default label's text to nil.

Here's a quick code sample that should work out of the box (Make sure you define self.testButton though):

TOMSMorphingLabel *animatedButtonLabel = [[TOMSMorphingLabel alloc] init];
animatedButtonLabel.frame = self.testButton.bounds;
animatedButtonLabel.text = @"Your animated text goes here";
 [self.testButton addSubview:animatedButtonLabel];

Note: By setting your TOMSMorphingLabel's frame to it's superView's bounds (Your UIButton in this case) you can insure that it'll cover the entire button area. I would recommend setting it's background to clearColor, so that if you want to animate the touch of the button, it's still visible. @cytryn hope this helps.

vicc avatar Mar 13 '15 00:03 vicc

Great idea... :+1:

tomknig avatar Mar 13 '15 10:03 tomknig

@TomKnig No problem. Anything to help. Maybe you could add an example in the demo and / or description for others to easily come across. :sunglasses:

vicc avatar Mar 16 '15 22:03 vicc

Cool! I'll do that as soon as possible and let you know! :)

tomknig avatar Mar 17 '15 08:03 tomknig