问题
I want to be able to make the text fade in a uitextfield when I change it. I've tried
[UIView animateWithDuration:0.25 animations:{
textview.text = @"";
}];
but that didn't work. It would be easier if I could access the textfields UILabel, but I don't se any!
Oh, and btw, I only want the text to be faded NOT the whole field
Any help is appreciated! - JomanJi
回答1:
You need to set the alpha of "textview" to the value you want to fade it to:
[UIView animateWithDuration:0.25 animations:{
textview.alpha = 0;
}];
UPDATE:
The text field itself is not accessible. The "textColor" property isa not animatable, so that's out as well. Your best bet is to separate the graphical styling from the label and put it in a separate view behind the label. This way you can fade out the label without removing the border and BG color or however you have the label styled.
回答2:
Try something like this:
CATransition *transition = [CATransition animation];
transition.duration = 0.15;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[textField.layer addAnimation:transition forKey:nil];
textField.text = @"some new text"; // or nil
It works not only with text fields. I used it with UIImageView
回答3:
If you want a great set of shared classes and extensions that includes a UIView extension with fadeIn() and fadeOut() functions, checkout the pod "SwifterSwift"
http://swifterswift.com/docs/Extensions/UIView.html
Pull in the cocoapod:
pod 'SwifterSwift'
You can then use something like:
textview.fadeIn()
来源:https://stackoverflow.com/questions/17025624/fade-uitextfield-text