2012-06-13 2 views
-1

가능한 중복 :
How to animate the background color of a UILabel?UILabel의 배경색 변경 점차

할리, 나는 그때 스위치를 가지고 있고 나는에 전환 할 때, 흰색 배경 색상이있는 UILabel의를했습니다 action은 배경색을 검정색으로 변경합니다. 이 색상을 점진적으로 변경하는 모드가 있습니까? 나는 색깔을 즉시 바꾸고 싶지 않지만 꺼지는 효과를 창출한다. 감사합니다. .

답변

1

코어 애니메이션 또는 UIView 애니메이션을 사용할 수 있습니다.

//viewDidLoad 

    //Initial Color of White 
    label.backgroundColor = [UIColor whiteColor]; 

    //Animate to black color over period of two seconds (changeable) 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:2];    //Change the "2" to the desired duration 

    label.backgroundColor = [UIColor blackColor]; 

    [UIView commitAnimations]; 

이 코드는 반드시 viewDidLoad 일 필요는 없습니다. 어디에서나 호출 할 수 있지만 UIView 애니메이션이고 Core Animation 애니메이션이 아니기 때문에 다른 UIView 애니메이션과 동시에 실행할 수 없습니다.

희망이 도움이됩니다.