0

在我的 Mac 上,我使用 NSPrintInfo 和 [NSPrintInfolocalizedPaperName] 来确定默认纸张尺寸是“US Letter”还是“A4”。

NSPrintInfo * printInfo = [NSPrintInfo sharedPrintInfo]; [printInfo 本地化纸张名称]

如何让 iOS 设备告诉我默认纸张尺寸是“US Letter”还是“A4”?

4

2 回答 2

3

由于没有人提出更好的方法,我通过获取 NSLocaleCountryCode 查找了哪些国家/地区使用了美国字母并开始检查此列表

 [[[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"]
于 2014-03-14T11:37:40.280 回答
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";
}
于 2018-04-11T11:03:41.573 回答