iPhone 的 UILabel 上淡出图像但不淡出文本

发布于 2024-09-29 12:52:12 字数 292 浏览 1 评论 0原文

我有一个标签,我添加了一个背景,如下所示:

myLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"some image"]];

用户将在标签中输入文本,完成后,我希望背景图像消失但保留文本。我已经尝试过 UIView 动画,但 UIImage 并未继承自 UIView,因此该方法不起作用,我有点卡住了。我需要以不同的方式向标签添加背景图像,或者以不同的方式设置动画以实现淡出。任何想法将不胜感激。

I have a label I have added a background to like this:

myLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"some image"]];

The user will enter text into the label and when finished, I would like to have the background image fade away but have the text remain. I've tried UIView Animations but UIImage does not inherit from UIView so that method has not worked and I am a bit stuck. Either I need to add a background image to my label differently or animate in a different way to get the fade out. Any thoughts would be appreciated.

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

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

发布评论

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

评论(1

一人独醉 2024-10-06 12:52:12

为什么不直接使用 UIView,在其中添加另一个带有背景的 UIView 和顶部的 UILabel,就像这样?

UI视图

  • UI视图
  • UILabel(使用 [UIColor clearColor] 作为背景颜色)

然后你可以淡出第二个UIView,UILabel将保持可见。作为backgroundColor)

Why not just use a UIView where you add both another UIView with your background, and a UILabel on top, like so?

UIView

  • UIView
  • UILabel (with [UIColor clearColor] as backgroundColor)

Then you can fade out the second UIView, and the UILabel will remain visible.as backgroundColor)

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