什么是使UILabel发光并看起来明亮的最佳方法? [英] What is best way to make UILabel Glow and look bright?

查看:123
本文介绍了什么是使UILabel发光并看起来明亮的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让UILabel显示了当前时间,我希望该时间(UILabel)在屏幕上发光,我尝试了许多通过google找到的答案,但没有人能正常工作, 需要这样的、、、

I made UILabel showing current time, I want that time(UILabel) glow on the screen, I tried many answers which I found via google, but no one is properply working, need like this ,,,

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

我尝试了如下的思考,

在ViewDidLoad

In 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];

为了使背景变黑,我照做了

for making background black, then I did as

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之后

after ViewDidLoad

在方法drawTextInRect的主体中,我按如下操作

In the body of method drawTextInRect, I did as follow

 - (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秒后更新,即使您的计时器在一秒钟内被调用两次,

What should I do ? I don't want to inherit UILabel and make new class, because it will make heavy when u update every second, then it will update after 2 or 3 seconds, even your timer is being called twice in one second,

有什么建议吗?

推荐答案

看看这个: 实用论坛

或者也许是这样: Stackoverflow

这篇关于什么是使UILabel发光并看起来明亮的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆