在我的Mac上,我使用NSPrintInfo和[NSPrintInfo localizedPaperName]来确定默认纸张尺寸是否为" US Letter"或" A4"。
NSPrintInfo * printInfo = [NSPrintInfo sharedPrintInfo]; [printInfo localizedPaperName]
如何让iOS设备告诉我默认纸张尺寸是否为" US Letter"或" A4"?
答案 0 :(得分:3)
由于没有人提出更好的方法,我通过获取NSLocaleCountryCode来查找使用US letter的国家并开始检查此列表
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"US"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"CA"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"MX"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"CU"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"DO"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"GT"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"CR"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"SV"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"HN"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"BO"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"CO"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"VE"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"PH"]||
[[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] isEqualToString:@"CL"]
答案 1 :(得分:0)
我使用类似的固定列表方法,如@ spacecash21建议,基于此地图: https://en.wikipedia.org/wiki/Paper_size#/media/File:Prevalent_default_paper_size.svg
+ (NSString*)defaultPaperName
{
// as it looks mostly US and Canada and the Philippines are actually using the US Letter format, usage of the metric system is no clue
// https://en.wikipedia.org/wiki/Paper_size#/media/File:Prevalent_default_paper_size.svg
static NSSet* letterCountries;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
letterCountries = [NSSet setWithArray:@[@"US", @"CA", @"MX", @"CU", @"DO", @"GT", @"CR", @"SV", @"HN", @"BO", @"CO", @"VE", @"PH", @"CL"]];
});
NSString* countryCode = NSLocale.currentLocale.countryCode;
if ([letterCountries containsObject:countryCode.uppercaseString])
return @"na-letter";
return @"iso-a4";
}