是否有任何Mac App Store兼容方法将桌面墙纸位置设置为“拉伸(stretch)至填充屏幕”?
最佳答案
This code sample from Apple很好地概述了该问题以及如何在Cocoa中对其进行正确编码。突出的代码段如下所示:
- (void)updateScreenOptions:(NSScreen*)screen
{
if (screen)
{
NSDictionary *screenOptions = [[NSWorkspace sharedWorkspace] desktopImageOptionsForScreen:curScreen];
// the value is an NSNumber containing an NSImageScaling (scaling factor)
NSNumber *scalingFactor = [screenOptions objectForKey:NSWorkspaceDesktopImageScalingKey];
[scalingPopup selectItemAtIndex:[scalingFactor integerValue]];
// the value is an NSNumber containing a BOOL (allow clipping)
NSNumber *allowClipping = [screenOptions objectForKey:NSWorkspaceDesktopImageAllowClippingKey];
[[clippingCheckbox cell] setState:[allowClipping boolValue]];
// the value is an NSColor (fill color)
NSColor *fillColorValue = [screenOptions objectForKey:NSWorkspaceDesktopImageFillColorKey];
if (fillColorValue)
[fillColor setColor:fillColorValue];
}
}
如some of the answer errata中所述,此处用来解决您问题的正确方法似乎是
[screenOptions setObject:scalingFactor forKey:NSWorkspaceDesktopImageScalingKey]
和[[NSWorkspace sharedWorkspace] setDesktopImageURL:imageURL forScreen:curScreen options:screenOptions error:&error]
,它们应该提供所需的功能。我自由地接受this was a collaborative effort,但似乎我们已经犯了一个错误,无法找到正确的解决方案。
(有关
NSImageScaling
枚举和 NSWorkspace
的附加信息,其中包含正确的缩放键。)