当其框架与UIView相交时,反向UIlabel文本颜色 [英] Inverse UIlabel text color when its frame intersects an UIView
问题描述
嗨我试图在标签rect与UIView相交的情况下改变UILabel的文本颜色,我想也许有一个属性或我可以使用的东西。如下图所示:
Hi Im trying to change the text color of a UILabel in the case when the labels rect intersects an UIView, i was thinking maybe there is a property or something i can use. Like in the image below:
以前是否有人遇到过此问题,或者我应该阅读什么才能开始做这件事?
Did someone meet this issue before, or what should i read to start doing this thing ?
谢谢提前
推荐答案
好难题!这就是我要做的事情:
Good puzzle! Here's what I would do:
- 两个UIViews。我们将一个称为背景,另一个称为progressBar。 progressBar在其常见的
superview
上堆叠在背景之上,具有相同的origin
。 - 他们两者都有一个UILabel作为子视图,两个标签相对于其父级具有相同的来源。 background有一个深色的
backgroundColor
,而且它的标签有浅textColor
,进度视图还有相反的东西。 - progressBar的帧宽比背景窄,并且
clipsToBounds == YES
- Two UIViews. Let's call one the background and the other the progressBar. progressBar is stacked on top of background with the same
origin
on their commonsuperview
. - They both have a UILabel as subview, and both labels at the same origin relative to their parent. background has a dark
backgroundColor
and it's label has lighttextColor
and the progress view has things the other way around. - progressBar has a narrower frame width than background and has
clipsToBounds==YES
诀窍是,视图的起源相同,标签的起源相同,而顶视图中的clipsToBounds,一切看起来都是正确的。
The trick is, with the views' origins the same and the labels' origins the same, and clipsToBounds on the top view, everything is going to look right.
将这两个视图放入一个名为ReallyCoolProgressView的新UIView子类中,并给它一个公共方法:
Drop those two views into a new UIView subclass called ReallyCoolProgressView, and give it one public method:
- (void )setProgress :( float)progress
progress是一个从0.0到1.0的数字。该方法缩放progressBar宽度并设置两者标签的文本 @Progress%f,进度* 100
-(void)setProgress:(float)progress
progress is a number from 0.0 to 1.0. The method scales the progressBar width and sets both label's text @"Progress %f", progress*100
这篇关于当其框架与UIView相交时,反向UIlabel文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!