如何在 iOS 中屏蔽 UILabel - Objective-C
我想对 UIView 进行子类化,并将四个 UILabels 放在另一个之上;顶部标签将是掩模,第二个标签将是带有文本的普通标签,第三个标签是具有纯色背景且没有文本的标签。底部标签将与顶部第二个标签相同,但字体颜色不同。当我发送第三个标签的宽度时,它将覆盖底部标签,显示文本的部分视图。我想让第二个文本为一种颜色,而未覆盖的底部标签显示另一种颜色字体。
这可能吗?如果有人可以解释如何在 Objective-C 中进行屏蔽,那也会有帮助。
我试图构建一个像进度条一样的 UIView,当进度条填充到 60% 时,我希望顶部文本以白色字体颜色显示,而底部文本以不同颜色显示。
I want to sub-class a UIView and place four UILabels over top one another ; top label will be the MASK, 2nd label will be a normal label with text, the 3rd label is a label with solid background with no text. the bottom label will the same as the top 2nd label with a different color font. when i sent the width of the third label it will cover up the bottom label showing a partial view of the text. I want to have the 2nd text be one color while the uncoverd bottom label display another color font.
Is this possibe? If someone can explain how to mask in objective-C that will help too.
I trying to build a UIView that acts like a progress bar, as the bar fill to 60%, I want to top text to show in white font color, when the bottom text shows in a different color.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用两个 UILabel 来完成此操作,一个位于底部,一个嵌入在顶部的另一个视图中。
然后,当您想要更改进度时,您可以设置
topContainer
的宽度。这应该剪辑topLabel
。You could do it with two UILabels, one on the bottom, and one embedded in another view on top.
Then, when you want to change the progress, you'd set the width of
topContainer
. This should cliptopLabel
.与其使用四个 UILabel,为什么不子类化 UILabel 并在
drawRect:
方法中自己绘制它呢?它看起来像:为了方便起见,您可以为子类创建遮罩图像和替代字体属性。
Rather than using four UILabels, why not subclass UILabel and draw it yourself in the
drawRect:
method? It would look something like:You could make the masking image and the alternate font properties of your subclass, for convenience.