Problem with NSColors in cocoa

前端 未结 3 595
清酒与你
清酒与你 2021-01-16 11:07

i am trying to compose colors using NSColor and when i am trying to create RGB color with the following values it just displays the white colors instead:

(r,         


        
3条回答
  •  天命终不由人
    2021-01-16 11:48

    NSColor components have values in [0..1] so you should normalize the values you have, e.g.:

    NSColor * myColor = [NSColor colorWithDeviceRed:100.0/255 green:100.0/255 blue:100.0/255 alpha:1.0];
    

    If you try to set values greater then 1 to colour components then they're interpreted as 1, so your code will be actually equivalent to

    NSColor * myColor = [NSColor colorWithDeviceRed:1.0 green:1.0 blue:1.0 alpha:1.0];
    

    Which creates white colour.

提交回复
热议问题