UIBarButtonItem 中的 UIButton 未显示
我的视图中确实加载了以下内容在我的表视图控制器上:
UIButton *change_view = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[change_view setTitle:@"List" forState:UIControlStateNormal];
[change_view addTarget:self action:@selector(toggleView:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView: change_view];
self.navigationItem.rightBarButtonItem = button;
当我运行程序时,它不显示任何标题或圆角矩形按钮。但是,如果我将类型更改为 UIButtonTypeInfoLight,它将显示出来......那么问题是什么?
I have the following in my view did load on my table view controller:
UIButton *change_view = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[change_view setTitle:@"List" forState:UIControlStateNormal];
[change_view addTarget:self action:@selector(toggleView:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView: change_view];
self.navigationItem.rightBarButtonItem = button;
When I run the program, it doesn't show any title or the rounded rectangle button. However, if I change the type to UIButtonTypeInfoLight, it will show up... so what is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我更喜欢下面的方法来设置按钮的边界。
I'd prefer the way below to set the button's bounds.
尝试为您的
change_view
设置适当的框架。当您使用
UIButtonTypeInfoLight
类型按钮时,使用一些内置尺寸(可能取决于所使用的图标),并应用UIButtonTypeRoundedRect
类型默认框架,该框架必须是CGRectZero
直角。Try to set an appropriate frame to your
change_view
.When you use
UIButtonTypeInfoLight
type button uses some built-in size (likely depended on icon used for it), withUIButtonTypeRoundedRect
type default frame is applied which must beCGRectZero
rect.