4

現在の時刻を表示するUILabelを作成しました。その時刻(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を継承して新しいクラスを作成したくないのは、uが毎秒更新されると重くなり、2〜3秒後に更新され、タイマーが1秒間に2回呼び出されている場合でも更新されるためです。

なにか提案を?

4

2 に答える 2

2

これを見てください: 実用的なフォーラム

または多分これ: Stackoverflow

于 2011-07-07T15:56:41.710 に答える
0

GitHubでこのコードを見てください。見た目は素晴らしいですが、これまでのところ、io7で動作するようにしています。ここに更新を投稿します。

https://github.com/andrewgleave/TextGlowDemo

于 2014-02-22T14:09:00.123 に答える