Chameleon icon indicating copy to clipboard operation
Chameleon copied to clipboard

UIButton title blurry

Open raytrodd opened this issue 13 years ago • 4 comments

I am running into an issue where a UIButton with a simple title is being shown with blurry text. The code below renders a UILabel and an UIButton with the same font name and size. The UILabel shows is rendered clearly, but the UIButton appears blurry:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
  window.backgroundColor = [UIColor lightGrayColor];
  window.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  
  
  UILabel* sillyLabel = [[UILabel alloc] init];
  sillyLabel.text = @"silly label";
  sillyLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
  sillyLabel.textColor = [UIColor darkGrayColor];
  sillyLabel.frame = CGRectMake(22, 100, 60, 50);
  sillyLabel.backgroundColor = [UIColor clearColor];
  [window addSubview:sillyLabel];
  
  UIButton* sillyButton = [UIButton buttonWithType:UIButtonTypeCustom];
  sillyButton.titleLabel.textAlignment = UITextAlignmentLeft;
  [sillyButton setTitle:@"silly button" forState:UIControlStateNormal];
  [sillyButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
  sillyButton.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
  sillyButton.frame = CGRectMake(22,125,60, 50);
  [window addSubview:sillyButton];
  
  
  [window makeKeyAndVisible];
    return YES;
}

I verified that this code results in the correct behavior in iOS.

raytrodd avatar Sep 21 '11 00:09 raytrodd

This appears to be related to the _defaultTitleShadowColor. When a shadowColor is not specified, UIButton is defaulting to white. This seems to cause the symptom detailed above. I made this change locally, and the buttons appear the same on ios and chameleon.

 - (UIColor *)_defaultTitleShadowColor
 {
-    return [UIColor whiteColor];
+    return nil;
 }

raytrodd avatar Sep 21 '11 03:09 raytrodd

what's happening if you force to render on the pixel grid?

CGRectMake(22.5f, 100.5f ...

ghost avatar Oct 09 '11 17:10 ghost

It looks better, but it still looks smudged and quite different than the normal ios rendering.

raytrodd avatar Oct 16 '11 23:10 raytrodd

Quartz is a different animal for different purposes iOS rendering is doing a lot to help kidos, on the the desktop you have to be mature, let's say do the same for your super container? I am sure your button is in handmade container, moreover it would be foolish to think to get the same rendering as the screens are physically quite different, say pixel wide for instance.

to accomplish this facsimile, this UKKit port should relay on a CoreGraphics placeholder where frames and bounds shadows rendering are adapted to auto-correct the developer "inputs" like the iOS does and for my taste too much, but Apple wanted to attract a large number of devs even the less gifted.

here we are typically in what we call cross platform developments, it's like the web, different browsers, different platforms, but your code has to take account of the reality else you don't get paid.

You should read more about Quartz 2D and PostScript rendering, and here is the mistake logging that as an issue because you did not take account that Quartz is a different Graphic engine with its own logics, this UIKit port is not meant to do your job, it's a set of class wrapping the UIKit hierarchy.

ghost avatar Oct 17 '11 22:10 ghost