我不应用 setFrame:CGRectMake
[Button1 setFrame:CGRectMake(0, 0, 50, 0)];
[Button2 setFrame:CGRectMake(0, 0, 120, 0)];
[Button3 setFrame:CGRectMake(0, 0, 50, 0)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Button1];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Button2];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Button3];
我想在导航栏中添加按钮。导航栏有 3 个按钮。
像这样的导航组合。
button 1 button 2 text button3
但我没有表现出这一点。这个喜欢。
button 2 text button3
Button1、Button2 和 Button3 是图像。
我认为 Button1 setFrame 不起作用。
我认为 setFrame:CGRectMake(0,0,50,0) 适用于 Button1,setFrame:CGRectMake(0,0,120,0) 适用于 Button2。因此,Button1 被 Button2 setFrame 擦除。
如何使用这个 Button1 setFrame ?
请帮我。
[Button1 setFrame:CGRectMake(0, 0, 50, 0)];
[Button2 setFrame:CGRectMake(0, 0, 120, 0)];
[Button3 setFrame:CGRectMake(0, 0, 50, 0)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Button1];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Button2];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Button3];
I want to add button in the NavigationBar. NavigationBar have 3 buttons.
Navigation Composition like this.
button 1 button 2 text button3
But I didn't show that. this like.
button 2 text button3
Button1, Button2 and Button3 are an Image.
I thought that Button1 setFrame didn't work.
I think setFrame:CGRectMake(0,0,50,0) works Button1 and setFrame:CGRectMake(0,0,120,0) works Button2. so, Button1 is erased by Button2 setFrame.
How to work this Button1 setFrame ?
Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它与 setFrame: 调用无关。您不能将两个按钮分配给
leftBarButtonItem
。第二个分配将覆盖第一个分配。您应该创建一个空白视图,将两个按钮添加到该视图中(正确设置它们的框架,以便它们并排放置),然后使用该容器视图创建一个栏按钮项。It has nothing to do with the
setFrame:
calls. You cannot assign two buttons toleftBarButtonItem
. The second assignment overwrites the first. You should create a blank view, add the two buttons to this view (setting their frames correctly so that they are located side by side), and then create a bar button item with this container view.