开发者

Saving images to Iphone photo library

I am totally new to objective-c and I need to do an app which allows user to download wallpapers to his photo l开发者_如何学Pythonibrary, I have 6 wallpapers on the "wallpaper view" that are downloadable, so how should I start this off? Where should I store the wallpapers? Is storing them in Resources folder viable? My current issue is that I have no idea how to load them and write them to the photo library.


If the images are unchangeable you can embed them in resource folder, otherwise you can host them on server, and reload them at every app relaunch.

You can represent them via UIButton, and after click on image, save it to the photo library.

For loading images that are embedded in resource use:

UIImage* img = [UIImage imageNamed:@"imageName.png"];

Or you could get images from internet, by:

UIImage* img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://yoursite.com/image.png"]]];

For creating button, with image, use:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
btn.frame = CGRectMake(40, 140, 240, 30);
[btn addTarget:self action:@selector(downloadImage:) forControlEvents:UIControlEventTouchUpInside];
[btn setImage:img forState:UIControlStateNormal];
[self.view addSubview:btn];

And when you have image, you can save it to the photo library with:

UIImageWriteToSavedPhotosAlbum(img, nil,nil,nil);


You save photos to the library with

void UIImageWriteToSavedPhotosAlbum (
    UIImage  *image,
    id       completionTarget,
    SEL      completionSelector,
    void     *contextInfo
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜