Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Fuzzy graphics when CGRect given float value

joncjonc Posts: 313Registered Users
edited June 2008 in iOS SDK Development
Has anyone else noticed that UIObjects are fuzzy if you set any of their values in the rect of their frame to float values? This makes sense, but I wasn't sure if it was intended behavior. For example, I have a label that I wan't to place dynamically depending on the size of a cell's content view:
weightLbl.frame = CGRectMake((self.contentView.frame.size.width * 0.445), weightLbl.frame.origin.y, weightLbl.frame.size.width, weightLbl.frame.size.height);

If I use that line the label shows up a little bit "fuzzy" looking on the screen. I figured out a workaround though, I just have to cast the result of that multiplication as an int, like this:
weightLbl.frame = CGRectMake(((int)(self.contentView.frame.size.width * 0.445)), weightLbl.frame.origin.y, weightLbl.frame.size.width, weightLbl.frame.size.height);

I would think that it would convert the frame to an integer just thinking from a graphics perspective. Do you all think that is supposed to be happening?
Post edited by jonc on


  • scottiphonescottiphone Posts: 802Registered Users
    edited June 2008
    As I recall on the Mac the drawing happens at .5 for auto-antialias. You coudl try offsetting as well and see if that works.
  • BuschyBoyBuschyBoy Posts: 93Registered Users
    edited June 2008
    Just on the simulator or on the device itself, too?
  • joncjonc Posts: 313Registered Users
    edited June 2008
    I think it was on both the simulator and the phone actually. It could have been because I was accidentally (lol) laying out my view in the drawrect method of a table cell, but I had cast everything as an int before I took it out. It can confirm it was doing it in drawrect though. I will try it again when I get to work tomorrow because that is strange. It didn't look pretty like anti-aliasing, it looked fuzzy.

    It could have been that the tiny drop shadow on the text was making the anti-aliasing look like blur.
  • jeff_lamarchejeff_lamarche Posts: 420Registered Users
    edited June 2008
    The engine that drives the graphics on the iPhone (and the Mac) are designed to be device and resolution independent, so if you give it a floating point value, it will do its best to give you what you want, most likely by anti-aliasing the pixels on either side of the value you specified.

    That's my guess from working with Quartz on the Mac, though, I haven't dived much into custom drawing yet on the iPhone.
    <a href=""; target="_blank"><font color="red">Check out my iPhone Dev Blog</font></a><br />
    You can send me e-mail at my forum username at mac dot com.
  • joncjonc Posts: 313Registered Users
    edited June 2008
    That seems to be the what is happening so the iPhone must do it too. I didn't know that, it makes a lot more sense why everything looks prettier in Mac OS and on the iPhone.

    Try giving your text a drop shadow with a size of (0.5,0.5), it looks pretty.
Sign In or Register to comment.