17
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ใƒ—ใƒญใ‚ฐใƒฉใƒ ใงใƒ†ใ‚ญใ‚นใƒˆใฎ่‰ฒใ‚’่ƒŒๆ™ฏ่‰ฒใซๅฟœใ˜ใŸ่ฆ‹ใ‚„ใ™ใ„่‰ฒใซ่จญๅฎšใ™ใ‚‹

17
Last updated at Posted at 2016-01-08

ใƒ†ใ‚ญใ‚นใƒˆใฎ่‰ฒใฏๅ˜็ด”ใซ็™ฝใƒป้ป’ใฎใฟใง้™ๅฎšใ—ใพใ™ใ€‚
่‰ฒใฎๆ˜Žใ‚‹ใ•ใ‚’่จˆ็ฎ—ใ™ใ‚‹ใƒญใ‚ธใƒƒใ‚ฏใฏใ“ใกใ‚‰ใ€‚

ๅ‚่€ƒ Technique 2.2.1 [priority 3] Test the color attributes of the following elements for visibility:

Color brightness is determined by the following formula:
((Red value X 299) + (Green value X 587) + (Blue value X 114)) / 1000
Note: This algorithm is taken from a formula for converting RGB values to YIQ values. This brightness value gives a perceived brightness for a color.

The rage for color brightness difference is 125.

125 ใŒๅŸบๆบ–ใ‚‰ใ—ใ„ใงใ™ใŒใ€ใฉใกใ‚‰ใŒใฉใ†ใชใฎใงใ—ใ‚‡ใ†ใ‹๏ผŸ

ๅ‚่€ƒ2 Check if UIColor is dark or bright?

If it is below 125, use white text. If it is 125 or above, use black text.

125 ใ‚ˆใ‚Šๅฐ‘ใชใ„ๅ ดๅˆใฏใ€่ƒŒๆ™ฏ่‰ฒใŒๆš—ใ„ใจใ„ใ†ใ“ใจใงใ™ใญใ€‚
ไธŠ่จ˜ใฎ้€šใ‚Šใซใ‚„ใฃใฆใฟใŸไพ‹ใŒไธ‹่จ˜ใงใ™ใ€‚

let red = 0.0, green = 0.0, blue = 0,0, alpha = 0.0

// ใใ‚Œใžใ‚Œใฎๅผ•ๆ•ฐใซๆŒ‡ๅฎšใ—ใŸๅค‰ๆ•ฐใซๅ€คใŒ่ฟ”ใ‚Šใพใ™ใ€‚
uiview.backGroundColor.getRed(&red, green: &green , blue: &blue, alpha: &alpha)

// red็ญ‰ใฎๅ€คใฏ 0.0 - 1.0 ใง่ฟ”ใ‚‹ใฎใง * 255 ใ—ใฆ RGB ใซใ™ใ‚‹
let delta = ((red * 255 * 299) + ( green * 255 * 587) + (blue * 255 * 114)) / 1000 

// 125 ใ‚ˆใ‚Šๅฐ‘ใชใ‘ใ‚Œใฐ่ƒŒๆ™ฏ่‰ฒใฏๆฟƒใ„่‰ฒใชใฎใงใ€ใƒ†ใ‚ญใ‚นใƒˆใฎ่‰ฒใฏ็™ฝใใ€้€†ใฏ้ป’ใ
if delta < 125 {
    textColor = UIColor.whiteColor()
}else{
    textColor = UIColor.blackColor()
}

ๅฎŸ้š›ใฏ delta ใฎๅ€คใ‚’่ฆ‹ใฆใ€ๆง˜ใ€…ใช่‰ฒใ‚’่จญๅฎšใ—ใฆใ‚‚่‰ฏใ•ใใ†ใงใ™ใ€‚

ๅฝ“็„ถใงใ™ใŒใƒญใ‚ธใƒƒใ‚ฏใฏๆ™ฎ้็š„ใชใ‚‚ใฎใชใฎใงใ€ iOS ใ ใ‘ใงใชใ Web ใ‚„ใใฎไป–ๆง˜ใ€…ใชๅ ด้ขใงๅˆฉ็”จใงใใใ†ใงใ™ใ€‚

17
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?