2013-11-26 158 views

回答

5

iPhone不提供UILabels這樣的功能,你需要爲動畫的標籤。

請參考以下鏈接 https://github.com/cbpowell/MarqueeLabel

只需拖放MarqueeLabel.h & MarqueeLabel.m文件,並創建標籤如下:

MarqueeLabel *rightLeftLabel = [[MarqueeLabel alloc] initWithFrame:CGRectMake(10, 260, self.view.frame.size.width-20, 20) rate:50.0f andFadeLength:10.0f]; 
rightLeftLabel.numberOfLines = 1; 
rightLeftLabel.shadowOffset = CGSizeMake(0.0, -1.0); 
rightLeftLabel.textAlignment = NSTextAlignmentRight; 
rightLeftLabel.textColor = [UIColor colorWithRed:0.234 green:0.234 blue:0.234 alpha:1.000]; 
rightLeftLabel.backgroundColor = [UIColor clearColor]; 
rightLeftLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17.000]; 
rightLeftLabel.marqueeType = MLRightLeft; 
rightLeftLabel.text = @"This text is not as long, but still long enough to scroll, and scrolls the same speed but to the right first!"; 
[self.view addSubview:rightLeftLabel]; 

他們創造UIView子類和動畫UILabels是子視圖UIView的。

希望這有助於你:)

1
 UILabel *toastLabel = [[UILabel alloc]init*]; 
    toastLabel.text = @"Our toast text"; 
    [toastLabel setHidden:TRUE]; 
    [toastLabel setAlpha:1.0]; 
    CGPoint location; 
    location.x = 0; 
    location.y = 400; 
    toastLabel.center = location; 
    location.x = 500; 
    location.y = 400; 
    [toastLabel setHidden:FALSE]; 
    [UIView animateWithDuration:8 animations:^{ 
     toastLabel.alpha = 0.0; 
     toastLabel.center = location; 
    }]; 
相關問題