1

使用两个rightBarButtonItem与图片在我的申请,我必须在UINavigationController在SWIFT 3.0使用两个rightBarButtonItem与形象,我张贴在下面的图片,在UINavigationController的,我已经在迅速

enter image description here

在给定的图像中,我非常担心创建帐户和登录rightBarbuttonItem的图像,我如何添加这些图像和按钮之间的边界完全像给定的样本。

任何帮助将是可观的。

+1

可以实现它通过添加UIButton&image&lable也 – iPatel

+0

@iPatel我已经尝试过,但没有用正确的语法在swift中做到这一点。 –

+2

@AbhishekMitra最简单的方法是创建一个UIView,并把它与它一起,然后创建使用customView初始化baritem初始化 –

回答

1

我的工作是在导航栏的标题视图中添加一个UIView,并根据需要进行扩展,然后您可以根据需要放置尽可能多的控件。

enter image description here

+0

谢谢@Anand它的工作,:)尼拉夫试图与他的指导相同,但我没有做到这一点,你的解释是明显的:) http://oi66.tinypic.com/2a78zug.jpg –

+0

快乐编码:) –

-1

可以帮你,但在的OBJÇ 1)创建按钮您准确你想要的宽度和高度,以及X和Y 2)做相同处理图像

UIButton *LoginButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[LoginButton addTarget:self action:@selector(yourLoginActionMethod) forControlEvents:UIControlEventTouchUpInside]; 
[LoginButton setFrame:CGRectMake(0, 0, 32, 32)]; 

UIButton *createAccount = [UIButton buttonWithType:UIButtonTypeCustom]; 
[createAccount addTarget:self action:@selector(yourSettingMethod) forControlEvents:UIControlEventTouchUpInside]; 
[createAccount setFrame:CGRectMake(44, 0, 32, 32)]; 

UIImageView *loginImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; 
UIImageView *settingImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; 

UIView *rightBarButtonItems = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 76, 32)]; 
[rightBarButtonItems addSubview:LoginButton]; 
[rightBarButtonItems addSubview:createAccount]; 
[rightBarButtonItems addSubview:loginImg]; 
[rightBarButtonItems addSubview:settingImage]; 

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBarButtonItems];