Blurry UILabel as programmatic subview of UITableViewCell contentView

后端 未结 9 821
离开以前
离开以前 2021-02-04 02:26

I am adding a UILabel instance as a subview of my custom UITableViewCell instance\'s contentView.

When I select the cell, the row

相关标签:
9条回答
  • 2021-02-04 02:48

    I ran into this problem myself today, and read somewhere that non-integer values for the origin and size of the UILabel's frame can cause this (I know they're floats, but you know what I mean). There has got to be a more elegant solution, but this quick hack appears to have solved the problem for me:

    self.valueLabel.frame = CGRectMake((int) frame.origin.x, (int) frame.origin.y, (int) frame.size.width, (int) frame.size.height);
    

    If you find a better solution, please let me know, I'd love to replace this hack with something a bit more tasteful.

    0 讨论(0)
  • 2021-02-04 02:51

    Setting shouldRasterize to YES may introduce blurriness. Set the rasterization scale and that should eliminate the blurriness. [self.layer setRasterizationScale:[[UIScreen mainScreen] scale]];

    0 讨论(0)
  • 2021-02-04 02:52

    Use round(); C functions are provided for a reason.

    #define roundCGRectValues (frame) \
    frame = CGRectMake(round(frame.origin.x),round(frame.origin.y),round(frame.size.width),round(frame.size.height));
    

    All you need.

    0 讨论(0)
  • 2021-02-04 02:55

    Sometimes the reason for the blurriness you have mentioned can be that labels's frame is beyond the cell frame. Even if you see all of your text you have put inside the label on your cell, the actual label size can be bigger than the cell frame.

    To check if that is the reason for the effect you see I would suggest to check/print all the data you have about labels size/location after it is instantiated and than check in the delegate method tableView:heightForRowAtIndexPath: that this fit into the cell height you are returning for the cell. Hope it will help in your case.

    0 讨论(0)
  • 2021-02-04 03:00

    The issue is sub-pixel rendering, which occurs when your origin (which is a float value) has a non-zero fractional component. Round to the nearest whole number and you should be fine.

    0 讨论(0)
  • 2021-02-04 03:11

    Ok found the problem, Make sure your parent view's coordinates are rounded as well.

    0 讨论(0)
提交回复
热议问题