简体   繁体   中英

How to invert text color in TextField depending on background

I have thumbnail image with TextField on it which shows the video length. How could I make it different from various background (thumbnail) colors?

白色可以带蓝色背

有白色背景时如何反转文本颜色

You can add shadow for your label to prevent situation on screenshot:

label.layer.shadowOpacity = 1
label.layer.shadowRadius = 0
label.layer.shadowColor = UIColor.black.cgColor
label.layer.shadowOffset = CGSize(width: 0, height: -1)

I decided to do all this stuff in Storyboard and finally, my solution is:

  • set background color to LightGray with Opacity 50% in Attributes inspector-View-Background-Other
  • mark "Clip to Bounds" below
  • add this two lines in Identity inspector-User Defined Runtime Attributes :

用户定义的运行时属性

And the result is:

结果

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM