Text color based on background image

后端 未结 2 1073
情歌与酒
情歌与酒 2020-12-04 18:36

My view has a background image with a text label overlay What\'s the best/good dynamic way to determine text color based on the background image so it can be readable (For n

2条回答
  •  清歌不尽
    2020-12-04 19:21

    My first though is to find the average color of the image and set the text color based on that. Of course, images can contain light and dark areas, so the color you choose could be unreadable at times.

    To find the average color of an image, try this:

    http://www.bobbygeorgescu.com/2011/08/finding-average-color-of-uiimage/

    Once you have the average color, check the red, green, and blue values. If they are "high enough" (whatever you define that as), use dark text, else use light text.

提交回复
热议问题