小编Est*_*her的帖子

以编程方式更改桌面映像

我正在尝试更改桌面图像; 我提出的程序如下.第一次运行此代码时,调整大小的图像在屏幕上显示为壁纸,但下次没有反应.我究竟做错了什么?

-(IBAction)click:(id)sender
{
    NSData *sourceData;
    NSError *error;
    NSFileManager *filemgr;
    filemgr = [NSFileManager defaultManager];
    screenArray = [NSScreen screens];
    screenCount = [screenArray count];
    unsigned index  = 0;

    for (index; index < screenCount; index++)
    {
        screenz = [screenArray objectAtIndex: index];
        screenRect = [screenz visibleFrame];

    }
    NSLog(@"%fx%f",screenRect.size.width, screenRect.size.height);

    arrCatDetails = [strCatDetails  componentsSeparatedByString:appDelegate.strColDelimiter];

    NSString *imageURL = [NSString stringWithFormat:@"upload/product/image/%@_%@_%d.jpg",[arrCatDetails objectAtIndex:0],appDelegate.str104by157Name,iSelectedImgIndex];
    NSString *ima = [imageURL lastPathComponent];
    NSString *str = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString *dataFilePath = [str stringByAppendingPathComponent:ima];
    NSString *imagePath = [NSString stringWithFormat:@"file://localhost%@",dataFilePath];
    NSURL *url = [[NSURL alloc] …
Run Code Online (Sandbox Code Playgroud)

macos desktop cocoa objective-c

2
推荐指数
1
解决办法
3679
查看次数

标签 统计

cocoa ×1

desktop ×1

macos ×1

objective-c ×1