Search code examples
iphoneuiimageviewalpha-transparency

Alpha value for imageView keeps changing in Interface Builder


I am setting the alpha value in IB to 0.1 of an imageView os it is slightly transparent. But for some reason, IB keeps changing that value to 0.100000001490116. Any idea why that is? I can of course set it programatically to 0.1 to make sure it has my desired value. But still would be nice to understand, why IB applies that change.


Solution

  • That number cannot be exactly defined by the floating point format. Try this in code:

    CGFloat foo = 0.1f;
    NSLog(@"foo = %.12f", foo);
    

    The result is "foo = 0.100000001490", exactly what you get.