gpt4 book ai didi

ios - 基于背景图像的文本颜色

转载 作者:技术小花猫 更新时间:2023-10-29 11:13:00 26 4
gpt4 key购买 nike

我的 View 有一个带有文本标签覆盖的背景图像什么是基于背景图像确定文本颜色的最佳/好的动态方式,以便它可以阅读(目前,我只对确定文本颜色应该是深色还是浅色感兴趣)

谢谢:)

最佳答案

找到woz提到的链接的平均颜色

然后设置文本样式

CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0;
[averageColor getRed:&red green:&green blue:&blue alpha:&alpha];

int threshold = 105;
int bgDelta = ((red * 0.299) + (green * 0.587) + (blue * 0.114));

UIColor *textColor = (255 - bgDelta < threshold) ? [UIColor blackColor] : [UIColor whiteColor];

像这样。

您还可以使用上面的链接从图像中获取 UIColor 并使用 matt's category使 UIColor 变亮或变暗。

关于ios - 基于背景图像的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19456288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com