gpt4 book ai didi

iphone - 无法将栏按钮添加到 UIToolBar

转载 作者:行者123 更新时间:2023-11-28 22:24:09 25 4
gpt4 key购买 nike

我想在我的应用程序中创建静态页脚。我使用了 UIToolbar。现在我想添加一些带有自定义照片的按钮。工具栏工作正常,但不显示按钮。

这是我用来添加按钮的代码:

UIImage *facebookImage=[[UIImage alloc]initWithContentsOfFile:@"facebook.png"];
UIImage *twitterImage=[[UIImage alloc]initWithContentsOfFile:@"twitter.png"];
UIImage *messageImage=[[UIImage alloc]initWithContentsOfFile:@"message.png"];
UIImage *emailImage=[[UIImage alloc]initWithContentsOfFile:@"email.png"];


UIBarButtonItem *facebook=[[UIBarButtonItem alloc]initWithImage:facebookImage style:UIBarButtonItemStyleBordered target:Nil action:Nil];
UIBarButtonItem *twitter=[[UIBarButtonItem alloc]initWithImage:twitterImage style:UIBarButtonItemStylePlain target:Nil action:Nil];
UIBarButtonItem *message=[[UIBarButtonItem alloc]initWithImage:messageImage style:UIBarButtonItemStylePlain target:Nil action:Nil];
UIBarButtonItem *email=[[UIBarButtonItem alloc]initWithImage:emailImage style:UIBarButtonItemStylePlain target:Nil action:Nil];

NSArray *toolbarButtons = [NSArray arrayWithObjects: facebook, twitter,email,message, nil];
[Footer setItems:toolbarButtons];

最佳答案

在您的代码更改中:

UIImage *facebookImage=[[UIImage alloc]initWithContentsOfFile:@"facebook.png"];
UIImage *twitterImage=[[UIImage alloc]initWithContentsOfFile:@"twitter.png"];
UIImage *messageImage=[[UIImage alloc]initWithContentsOfFile:@"message.png"];
UIImage *emailImage=[[UIImage alloc]initWithContentsOfFile:@"email.png"];

与:

UIImage *facebookImage= [UIImage imageNamed:@"facebook.png"];
UIImage *twitterImage= [UIImage imageNamed:@"twitter.png"];
UIImage *messageImage= [UIImage imageNamed:@"message.png"];
UIImage *emailImage= [UIImage imageNamed:@"email.png"];

如果你想使用 - (id)initWithContentsOfFile:(NSString *)path 方法你应该得到文件的完整路径名:

NSString* Path = [[NSBundle mainBundle] pathForResource:@"your_file_name" 
ofType:@"the_file_extension"];

关于iphone - 无法将栏按钮添加到 UIToolBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19466192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com