2

I have a view where I programmatically set a UILabel in viewDidLoad. The text on that label is blurry. The code:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];

    [self setTitle:tAddSystemScreenTitle];
    CGRect rect = CGRectMake(10,0,300,80);
    UILabel *messageLabel = [[UILabel alloc] initWithFrame:rect];

    [messageLabel setOpaque:NO];
    if (shouldShowControlForRemoteAccess) {
        [messageLabel setText:kRemoteAccessInfoMessage];
        [messageLabel setNumberOfLines:2];
    } else {
        [messageLabel setText:kOneSystemAlreadyAssociatedAlertString];
        [messageLabel setNumberOfLines:4];

        rect.size.height += 30;
        [messageLabel setFrame:rect];

        rect = dataTable.frame;
        rect.origin.y += 30;
        rect.size.height -= 30;
        [dataTable setFrame:rect];
    }
    NSLog(@"x: %f, y: %f, w: %f, h: %f", messageLabel.frame.origin.x, messageLabel.frame.origin.y, messageLabel.frame.size.width, messageLabel.frame.size.height);
    [messageLabel setBackgroundColor:[UIColor clearColor]];
    [messageLabel setShadowColor:[UIColor blackColor]];
    [messageLabel setTextColor:[UIColor blackColor]];
    [messageLabel setTextAlignment:UITextAlignmentLeft];
    [messageLabel setShadowOffset:CGSizeMake(0,-1)];
    [self.view addSubview:messageLabel];

    NSLog(@"x: %f, y: %f, w: %f, h: %f", self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);

    [dataTable setScrollEnabled:NO];

    [messageLabel release], messageLabel = nil;
}

When I checked what the frame values were, I got the following:

x: 10.000000, y: 0.000000, w: 300.000000, h: 80.000000

Checking the same for self.view gets:

x: 0.000000, y: 20.000000, w: 320.000000, h: 460.000000

The only other questions I could find on this issue suggested that I needed integer numbers for the frame, but as you can see I already have integer numbers. I tried the solution they recommended, using CGRectIntegral(rect) to replace all the places I had just rect, but that didn't work. How do I prevent the text from blurring?

Community
  • 1
  • 1
thegrinner
  • 11,546
  • 5
  • 41
  • 64
  • Are you sure the frame of the parent view has rounded float values? – rdougan Jan 24 '13 at 17:09
  • I just logged the same values for `self.view`, looks like they're all integers. – thegrinner Jan 24 '13 at 17:12
  • According to the label rect, it cannot be blurry. This means that logically it must be a parent. Perhaps a parent of the view, or even higher? Is it in a scrollview? Maybe the contentOffset of the scrollView is not rounded? – rdougan Jan 24 '13 at 17:14
  • I checked the class of `self.view` with `NSStringFromClass([self.view class])` and it reports back as a UIView. The `dataTable` is a `UITableView`, also with integer frame settings: `x: 0.000000, y: 80.000000, w: 320.000000, h: 360.000000`. – thegrinner Jan 24 '13 at 18:21
  • It looks like there's a footer view for dataTable, but that also has an integer frame... – thegrinner Jan 24 '13 at 18:23
  • Please post a screen shot. – rob mayoff May 02 '13 at 04:48

2 Answers2

1

I had the same problem. In my case the reason was that I was calling setShouldRasterize on the parent view.

oskare
  • 1,061
  • 13
  • 24
0

Perhaps it is the fact that you have black text with an ever so slightly offset black shadow, which makes it look blurry. Try removing your shadowColor and shadowOffset lines and see how it looks.

lnafziger
  • 25,760
  • 8
  • 60
  • 101