現在の時刻を表示する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回呼び出されている場合でも更新されるためです。
なにか提案を?