【问题标题】:UIToolBar item coordinatesUIToolBar 项目坐标
【发布时间】:2012-12-05 10:41:55
【问题描述】:

我的问题如下:我想知道工具栏项目的坐标,以便我可以在那里弹出一些数据。这些 barbuttonitems 从不向我显示框架属性。
有解决办法吗?

【问题讨论】:

    标签: iphone ios xcode uitoolbar


    【解决方案1】:

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

    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

    【讨论】:

      【解决方案2】:
      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;
      

      【讨论】:

        【解决方案3】:

        如果您是从 xib 文件创建工具栏,那么如果您在工具栏上有多个栏按钮,则需要在按钮之前和之后添加多个“灵活空格键按钮项”,直到获得所需的间距。 如果您是动态创建 UIToolbar,那么您需要动态添加灵活的按钮。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2010-11-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-07-26
          • 1970-01-01
          • 2011-01-31
          • 2010-10-10
          相关资源
          最近更新 更多