2012-12-05 39 views
1

我的问题是:我想知道一个工具栏项目的坐标,以便我可以在那里弹出一些数据。这些barbuttonitems从来没有透露我的框架属性。
有没有解决方法?UIToolBar项目坐标

回答

0

你可以使用,如果你想给间距。

UIBarButtonItem *fixedLeftSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil]; 

//用于添加自定义视图

UIButton *webButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [webButton setFrame:CGRectMake(0, 0, 50, 40)]; 
     [webButton setImage:[UIImage imageNamed:@\"webIcon.jpg\"] forState:UIControlStateNormal]; 
     [webButton addTarget:self action:@selector(goToWebPage) forControlEvents:UIControlEventTouchDown]; 


     UIBarButtonItem *webpageBtn = [[UIBarButtonItem alloc]initWithCustomView:webButton]; 
     [webpageBtn setTarget:self]; 
     [webpageBtn setAction:@selector(goToWebPage)]; 

    [toolbar setItems:[NSArray arrayWithObjects: webpageBtn,fixedLeftSpace,webpageBtn, nil]]; 

还请参阅link

0
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 210, 44)]; 
UIBarButtonItem *space = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; 
NSMutableArray* buttons = [[NSMutableArray alloc] initWithObjects:bt1,space,bt2,space,bt3, nil]; 

    [tools setItems:buttons animated:YES]; 

    UIBarButtonItem *toolsBtn = [[UIBarButtonItem alloc]initWithCustomView:tools]; 

    self.navigationItem.rightBarButtonItem = toolsBtn; 
0

如果要创建从厦门国际银行文件中的工具栏,那么你需要添加多个“灵活的空间栏按钮项”之前和之后的按钮工具栏,如果你多栏按钮,直到你得到想要的间距。 如果您要动态创建UIToolbar,则需要动态添加灵活的按钮。