我希望实现与iOS 7 iOS 7的新UILabel远程更新相同的效果。
如果你看这个屏幕:

(右边的那个)你会注意到UILabel文本的颜色是背景模糊的相册封面,没有黑色的面具。
目前,我有透明的UILabel textColor (http://cl.ly/SInK),我的代码类似于https://github.com/robinsenior/RSMaskedLabel
我的第一个假设是拥有这样的视图层次结构。
UIImageView (Light blurred image)
|
UIImageView/UIView (Dark blurred image or just a dark mask for the superview)
|
UILabel (And all my other view). 我希望UILabel在第一个UIImageView上有一个透明的文本颜色,而忽略第二个/掩码)。
为了达到这一效果,我无法用我的头脑去想一个解决方案。
发布于 2014-06-10 09:14:09
因为iOS 8苹果提供了一个新的类,UIVibrancyEffect,可以添加到UIVisualEffectView中。与UIBlurEffect相结合,可以获得与我上面截图完全相同的结果。
发布于 2014-02-19 21:00:40
我不认为你能直接用一个UILabel来完成这个任务。我所做的就是把它分解成几块:
如何只绘制标签的背景。为此,我从CGPathRef from string编译代码,将字符串转换为路径。然后,子类UILabel和添加下面的drawRect做了适当的事情。
-(void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
// Convert the attributed text to a UIBezierPath
CGPathRef path = [self.attributedText createPath];
// Adjust the path bounds horizontally as requested by the view
CGRect bounds = [self textRectForBounds:rect limitedToNumberOfLines:self.numberOfLines];
CGAffineTransform xform = CGAffineTransformMakeTranslation(bounds.origin.x, bounds.origin.y);
// Adjust the path bounds vertically because it doesn't seem to be taken into account yet
bounds = CGPathGetBoundingBox(path);
xform = CGAffineTransformTranslate(xform, 0., (self.bounds.size.height - bounds.size.height) / 2.);
// Apply the transform to the path
path = CGPathCreateCopyByTransformingPath(path, &xform);
// Set colors, the fill color should be the background color because we're going
// to draw everything BUT the text, the text will be left clear.
CGContextSetFillColorWithColor(ctx, self.textColor.CGColor);
// Flip and offset things
CGContextScaleCTM(ctx, 1., -1.);
CGContextTranslateCTM(ctx, 0., 0. - self.bounds.size.height);
// Invert the path
CGContextAddRect(ctx, self.bounds);
CGContextAddPath(ctx, path);
CGContextDrawPath(ctx, kCGPathEOFill);
// Discard the path
CFRelease(path);
// Restore gstate
CGContextRestoreGState(ctx);
}如果在界面生成器中创建UILabel,设置类,将背景色设置为清除,前景色设置为建议的填充颜色,则背景将显示文本所在的位置。
为了模糊通过标签显示的主体,我在标签下放置了一个带有大小约束的FXBlurView (https://github.com/nicklockwood/FXBlurView),以保持它们对齐。
你可以看到它都在这里工作,https://github.com/dwb357/TransparentLabel。
发布于 2013-11-12 06:25:09
颜色不均匀。但这实际上是“剪裁”,让模糊和有色的背景闪耀。
一种方法是为象形文字构造一个CGPath,将图形上下文剪辑到它们,然后清除上下文,留下黑色外的区域和菱形半透明的区域。
另一种方法是从这种大型模糊的彩色封面艺术中创建图案颜色,并在UILabel上使用此图案颜色。
https://stackoverflow.com/questions/19787238
复制相似问题