gpt4 book ai didi

iphone - 让 UILabel 发光并看起来明亮的最佳方法是什么?

转载 作者:行者123 更新时间:2023-12-03 19:19:24 25 4
gpt4 key购买 nike

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

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

有什么建议吗?

最佳答案

看看这个: Pragmatic Forums

或者也许是这样的: Stackoverflow

关于iphone - 让 UILabel 发光并看起来明亮的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6596718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com