Xcode:带有 UIButton 的壁纸

发布于 2024-10-21 13:20:56 字数 156 浏览 10 评论 0原文

我想制作一个 iPhone 壁纸应用程序。 现在,如果我有 100 张壁纸,我是否必须创建 100 个 nib 文件、100 个 .m 和 .h 文件以及 100 个 UIButton 来保存壁纸和 100 个 UIButton 来转到上一个或下一个壁纸? 还有其他方法可以做到这一点吗? 谢谢 !

I want to make an wallpaper iphone app.
Now if i have for example 100 wallpapers , do I have to create 100 nib files and 100 .m and .h files and 100 UIButtons for to save the wallpaper and 100 UIButton for to go to the previous or next wallpaper ?
Is there any other way to do this ?
Thanks !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

木槿暧夏七纪年 2024-10-28 13:20:56

是的,当然。
将您的一百张壁纸保存在资源文件夹中。其名称如下“wp_1.png”、“wp_2.png”等。
然后用按钮(上一个、下一个和保存)创建一个笔尖
在 uiviewcontroller 中,您将有一个 int 属性。例如你称它为 n 或类似的东西。我建议为您的壁纸添加另一个属性(UIImageView)然后您在视图控制器中实现这些方法。

-(void)awakeFromNib {
self.n = 1;
UIImage* wallpaper = [UIImage imageNamed:@"wp_1.png"];
UIImageView* view = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
self.wallpaper = view;
view.image=wallpaper;
[self.view addSubview:view];
}

-(IBAction)next:(id)sender {
self.n++; // increases n by 1;
[self.wallpaper removeFromSuperview];
NSString* name = [NSString stringWithFormat:@"wp_%i.png", self.n];
UIImage* wallpaper = [UIImage imageNamed:name];
UIImageView* view = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
self.wallpaper = view;
view.image=wallpaper;
[self.view addSubview:view];
}

类似的事情。希望有帮助

yes sure.
save your hundred wallpapers in the resources folder. The are named like this "wp_1.png", "wp_2.png" etc.
Then you create a nib with the buttons (previous, next and save)
In the uiviewcontroller you'll have an int property. For instance you call it n or something like that. I would suggest adding another property for your wallpaper (UIImageView) Then you implement the methods in the view controller.

-(void)awakeFromNib {
self.n = 1;
UIImage* wallpaper = [UIImage imageNamed:@"wp_1.png"];
UIImageView* view = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
self.wallpaper = view;
view.image=wallpaper;
[self.view addSubview:view];
}

-(IBAction)next:(id)sender {
self.n++; // increases n by 1;
[self.wallpaper removeFromSuperview];
NSString* name = [NSString stringWithFormat:@"wp_%i.png", self.n];
UIImage* wallpaper = [UIImage imageNamed:name];
UIImageView* view = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
self.wallpaper = view;
view.image=wallpaper;
[self.view addSubview:view];
}

something like that. hope that helps

薄情伤 2024-10-28 13:20:56

当然不是。我会使用 UITableView 来实现这一点。或者甚至更好的是看起来类似于 iPhone 上的“照片”应用程序的自定义视图。

您不想使用 UIButton 转到上一张或下一张照片。您想在分页模式下使用 UIScrollView。
但您一开始就不希望用户以这种方式浏览您的图像。

创建一个索引屏幕,其中包含一个 UIScrollView(这次是非分页)以及所有图像的缩略图。当点击其中一个时,它会以漂亮的动画放大,您可以使用我之前提到的分页 UIScrollView 轻弹到下一张或上一张图像。

你知道,就像照片应用程序一样。

Of course not. I would use a UITableView for that. Or even better a custom view that looks similar to the Photos app on the iphone.

You don't want to use a UIButton to go to the previous or next photo. You want to use a UIScrollView in paging mode.
But you don't want the user to browse through your images in that way in the first place.

Create a index screen that has a UIScrollView (non-paging this time) with thumbnails of all your images. And when one is tapped it zooms in with a nice animation and you can flick to the next or previous image with the paging UIScrollView I mentioned earlier.

You know, like the Photos app.

挽心 2024-10-28 13:20:56

在头文件(.h 文件)中添加类似的内容:

int n;
UIImageView*壁纸;
@property

(读写) int n;
@property(读写,保留)UIImageView*壁纸;

在实现 fil(.m 文件)中:

@synthesize n,壁纸;

in the header (.h file) add something like that:

int n;
UIImageView* wallpaper;
}

@property (readwrite) int n;
@property (readwrite, retain) UIImageView* wallpaper;

in the implemention fil (.m file) :

@synthesize n, wallpaper;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文