2011-07-06 18 views
4

我做的UILabel显示当前的时间,我想那个时候(的UILabel)发光在屏幕上,我尝试了很多的答案,我通过谷歌发现,但没有人properply工作, 需要这样,,,什么是使UILabel焕发和看起来明亮的最佳方式?

http://i.stack.imgur.com/4REJp.png

我尝试了一些认为像如下,

在viewDidLoad中

colorOne = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0]; 
colorTwo = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0]; 

//Create the gradient and add it to our view's root layer 
gradientLayer = [[[CAGradientLayer alloc] init] autorelease]; 
gradientLayer.frame = CGRectMake(0.0, 0.0, 320.0, 480.0); 
[gradientLayer setColors:[NSArray arrayWithObjects:(id)colorOne.CGColor,  (id)colorTwo.CGColor, nil]]; 
[self.view.layer insertSublayer:gradientLayer atIndex:0]; 

制作背景黑色,然后我一样

CGRect rect = CGRectMake(15, 130, 320, 200); 
    label = [[UILabel alloc] initWithFrame:rect]; 
    label.backgroundColor = [UIColor clearColor]; 
    dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; 
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; 
    [dateFormatter setTimeZone:[NSTimeZone localTimeZone]]; 
    currentDateTime = [NSDate date]; 
    [dateFormatter setDateFormat:@"hh:mm:ss "]; 

    label.font=[UIFont fontWithName:@"DBLCDTempBlack" size:60.0]; 
    label.textColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0]; 

    glowOffset = CGSizeMake(10.0, 2.0); 
    glowColor = label.textColor; 
    glowAmount = 150.0f; 
    //[self drawRect:rect]; 
    [self drawTextInRect:rect]; 

    [self.view addSubview:label]; 

viewDidLoad中

在方法drawTextInRect的身体之后,我也如下

- (void)drawTextInRect:(CGRect)rect { 

    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSaveGState(context); 

    CGContextSetShadow(context, glowOffset, glowAmount); 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 

    CGColorRef color = CGColorCreate(colorSpace, CGColorGetComponents(glowColor.CGColor)); 
CGContextSetShadowWithColor(context, glowOffset, glowAmount, color); 

    // [label drawTextInRect:rect]; 

    /* 
    I can't understand this because I tried an code which was doing glow but was making  class that inheriting UILabel, then making Label from that class 
    */ 

    CGColorRelease(color); 
    CGColorSpaceRelease(colorSpace); 
    CGContextRestoreGState(context); 
    } 

我该怎么办? 我不想继承UILabel并创建新类,因为当你每秒更新一次时它会变得沉重,那么它会在2或3秒后更新,即使你的计时器在一秒钟内被调用两次,

任何建议?

+0

为什么要关注子类化? –

+0

你不想继承UILabel并创建一个新类,因为'当你每秒更新时它会变得沉重'。我想你可能想重温继承... – jakev

+0

我看到了一个例子制作UILabel的子集,并添加了属性,输出的辉光非常棒,但是当你每秒更新一次时间(秒)时,它会变迟,所以我不想使用类的对象。 –

回答

相关问题