如何向 UILabel 添加反射。 IOS

发布于 2024-10-16 14:06:27 字数 780 浏览 4 评论 0原文

(新手)问题在这里。搜索但无法在任何地方找到这个具体答案...... 我想向 UILabel 添加反射(如果可能的话还可以添加发光)。我看到了苹果的反射项目代码,但它适用于 UIImage 而不是标签。

只需将其添加到一个简单的时钟中即可:

- (void)runTimer                    //Starts a timer which messages runClock every 0.5sec
{
    myTicker = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(runClock)
                                              userInfo:nil repeats:YES];
}

- (void)runClock
{
    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] 
                                  autorelease]; NSDate *date = [NSDate date]; 
    // This will produce a time that looks like "12:15:00 PM". 
    [formatter setTimeStyle:NSDateFormatterMediumStyle]; 

    [clockLabel setText:[formatter stringFromDate:date]];   
}

(newbie) question here. Searched but could not find this specific answer anywhere....
I want to add a reflection (and a glow if possible) to a UILabel. I saw apple's reflection project code but it works for a UIImage not label.

just adding it to a simple clock:

- (void)runTimer                    //Starts a timer which messages runClock every 0.5sec
{
    myTicker = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(runClock)
                                              userInfo:nil repeats:YES];
}

- (void)runClock
{
    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] 
                                  autorelease]; NSDate *date = [NSDate date]; 
    // This will produce a time that looks like "12:15:00 PM". 
    [formatter setTimeStyle:NSDateFormatterMediumStyle]; 

    [clockLabel setText:[formatter stringFromDate:date]];   
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反目相谮 2024-10-23 14:06:27

我写了一篇关于如何生成任何 UI 元素或元素组的反射的文章。罐装技术可以放入您的项目中,并且非常易于使用。源代码和文章可以在 http://aptogo.co.uk 找到/2011/08/无大惊小怪的反思/

I wrote an article on how to generate reflections of any UI element or group of elements. The canned technique can be dropped into your project and is really easy to use. Source code and the article can be found at http://aptogo.co.uk/2011/08/no-fuss-reflections/

踏月而来 2024-10-23 14:06:27

我认为正确的方法是子类化 UILabel 并使用quartz2d 重写drawRect 方法,

在这里你和quartz2d 可以更好地了解彼此。
这里是您和quartz2d 相互了解的地方好一点。

I think the right way would be subclassing UILabel and override the drawRect method using quartz2d

here's where you and quartz2d can get to know each other a little better.
here's where you and quartz2d can get to know each other a little better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文