将图标添加到 xcode 中的导航栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6183883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:09:39 来源:igfitidea点击:
Adding icons to navigation bar in xcode
提问by Christina
I want to add icon to the navigation bar present in my xcode project.Can anyone guide me through any method to do so and also i want to do it programmatically.Any help will be appreciated.
我想在我的 xcode 项目中的导航栏中添加图标。任何人都可以通过任何方法指导我这样做,我也想以编程方式进行。任何帮助将不胜感激。
Thanks, Christy
谢谢,克里斯蒂
回答by Jhaliya
回答by Aravindhan
IBOutlet UIImageView *image;
UIImage *image1=[UIImage imageNamed:@name.jpg"];
image=[[UIImageview alloc]initWithImage:image1];
image.frame=CGRectMake(0,0,320,400);
navigationbar.titleview=image;
EDIT: image to the right side:
编辑:右侧的图像:
UIButton* fakeButton = (UIButton *) [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage.png"]];
UIBarButtonItem *fakeButtonItem = [[UIBarButtonItem alloc] initWithCustomView:fakeButton];
self.navigationItem.rightBarButtonItem = fakeButtonItem;
[fakeButtonItem release];
[fakeButton release];
source:pevious so questions