I made a UILabel showing the current time, I want the time (UILabel) to be on the screen, I tried a lot of the answers that I found through Google, but no one works correctly, I need one,
http://i.stack.imgur.com/4REJp.png
I tried to think as shown below
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 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];
to create a black background, then I did it like
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;
after ViewDidLoad
In the body of the drawTextInRect method, I did the following
- (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);
What should I do? I donโt want to inherit UILabel and create a new class, because it will be very difficult when u is updated every second, after which it will be updated after 2 or 3 seconds, even your timer is called twice in one second,
any suggestion?