Chameleon
Chameleon copied to clipboard
UIButton title blurry
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.
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; }
what's happening if you force to render on the pixel grid?
CGRectMake(22.5f, 100.5f ...
It looks better, but it still looks smudged and quite different than the normal ios rendering.
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.