UIButton 在 iOS 中不显示
以下是在工具栏上显示按钮的代码。
UIButton myButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *myImage = [UIImage imageNamed:@"img1.png"];
[myButton setBackgroundImage:myImage forState:UIControlStateNormal];
UIBarButtonItem *myToolbarButton = [[UIBarButtonItem alloc] initWithCustomView:myButton];
工具栏上没有显示任何内容。请告诉我出了什么问题。
Following is a code to display a button to the toolbar.
UIButton myButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *myImage = [UIImage imageNamed:@"img1.png"];
[myButton setBackgroundImage:myImage forState:UIControlStateNormal];
UIBarButtonItem *myToolbarButton = [[UIBarButtonItem alloc] initWithCustomView:myButton];
Nothing gets displayed on the toolbar. Please tell me what is wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
或者如果它是导航栏
您还应该设置自定义按钮的框架,如下所示:
然后,如果您想添加选择器/回调:
OR if it's a navigation bar
Also you should set the frame for the custom button, something like this:
Then if you want to add a selector/callback:
其中 self 是 UIViewController。
Where self is a UIViewController.
您忘记将此按钮添加到工具栏!
如果你想在导航栏添加一个按钮,请使用这个:
另外,你应该记住设置
myButton
的框架:You forgot to add this button to the toolbar!
If you want to add a button to navigation bar, use this:
Also, you should remember to set the frame of
myButton
: