Open vicc opened 9 years ago
+1
tried some quick hacking here but with no good results =/
@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.
Great idea... :+1:
@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:
Cool! I'll do that as soon as possible and let you know! :)
I would love to see UIButton's label support the morphing effect! Great job btw!