我不应用 setFrame:CGRectMake

发布于 2024-08-20 15:29:37 字数 922 浏览 3 评论 0原文

[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 技术交流群。

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

发布评论

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

评论(1

安稳善良 2024-08-27 15:29:37

它与 setFrame: 调用无关。您不能将两个按钮分配给 leftBarButtonItem。第二个分配将覆盖第一个分配。您应该创建一个空白视图,将两个按钮添加到该视图中(正确设置它们的框架,以便它们并排放置),然后使用该容器视图创建一个栏按钮项。

It has nothing to do with the setFrame: calls. You cannot assign two buttons to leftBarButtonItem. 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.

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