title: how apple's music app defines which color to use for text to make them readable?
body: <p>i 'm trying to get the effect that apple's music app have , you've noticed that the text color is always stays readable no matter what is in background, for example : <a href="https://i.stack.imgur.com/htRNe.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/htRNe.jpg" alt="enter image description here"></a>
  see that green color on black background... </p>
  
  <p>i just want to make my text lighter(white) or darker(black) (according to background image's color )</p>
  
  <p>how can i do this ??</p>
  
  <p>yeah thats true similar questions were asked here before and i checked them too </p>
  
  <p>here's what i got </p>
  
  <p><a href="https://stackoverflow.com/questions/19456288/text-color-based-on-background-image">this</a> questions answer says to get the average color of image then see if image is darker or lighter and accordingly change the text color </p>
  
  <p>but that question is based on Obj C and also the way for getting the average color is in Obj C </p>
  
  <p>so how can i do this in swift ?? </p>