是否可以为Xcode中的UIToolbar设备创建滚动iOS?我正在使用Xcode版本4.5测试版。
ViewController.m⬇
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
myScrollView.contentSize = CGSizeMake(myToolBar.frame.size.width, myToolBar.frame.size.height);
}ViewController.h⬇
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UIScrollView *myScrollView;
IBOutlet UIToolbar *myToolBar;
IBOutlet UIBarButtonItem *toolbarItem;
}
@property (strong, nonatomic) UIWindow *window;
@end不工作:( )
发布于 2012-07-10 01:04:49
是的,这是可以做到的-只是尝试它(不是很好的UI设计,但也许它适合你的要求。)您必须设置滚动视图的contentSize。
添加一个UIScrollView到您的故事板。在其中添加一个UIToolBar,并使它尽可能宽(可能比UIScrollView更宽)。添加您需要的任何工具栏项。
使IBOutlets用于scrollView和工具栏(以及工具栏项)。然后在viewDidLoad中设置scrollView.contentSize
myScrollView.contentSize = CGSizeMake(myToolBar.frame.size.width, myToolBar.frame.size.height);更新
试试下面的代码,看看元素的实际尺寸是什么。
- (void)viewDidLoad
{
[super viewDidLoad];
myScrollView.contentSize = CGSizeMake(myToolBar.frame.size.width, myToolBar.frame.size.height);
CGRect myScrollViewRect = myScrollView.frame;
NSLog(@" myScrollView %f %f %f %f", myScrollViewRect.origin.x,
myScrollViewRect.origin.y,
myScrollViewRect.size.width,
myScrollViewRect.size.height);
CGRect toolbarRect = myToolBar.frame;
NSLog(@" toolbarRect %f %f %f %f", toolbarRect.origin.x,
toolbarRect.origin.y,
toolbarRect.size.width,
toolbarRect.size.height);
}我得到的输出如下。注意工具栏是如何比scrollView更宽的?如果你的不宽,它就不会滚动(它怎么可能-没有地方滚动)。
2012-07-10 14:29:34.494 Junk4275 4275:707 myScrollView 0.000000 605.000000 778.000000 128.000000 2012-07-10 14:29:34.498 Junk4275 4275:707 toolbarRect 0.000000 52.000000 1200.000000 44.000000
发布于 2012-07-10 00:16:10
我只需要自己去做。你不能。您能做的最好是放置一个工具栏,并在其之上添加一个UIScrollView。希望这能有所帮助。干杯!
发布于 2013-01-04 07:54:30
希望这能帮到一些人。我在这里找到了答案:How to add scrolling for buttons on UIToolbar?
基本上,您需要从超级视图中删除工具栏,重新设置工具栏的一些属性,将其设置为滚动视图的子视图,然后将滚动视图设置为最初删除的superview的子视图。都在那个环节里。对我来说是完美的。
https://stackoverflow.com/questions/11404911
复制相似问题