【问题标题】:Bar segmented control has padding in Toolbar on iOS7 iphone 5s real device在 iOS7 iphone 5s 真机上,Bar 分段控件在 Toolbar 中有填充
【发布时间】:2013-11-15 12:08:05
【问题描述】:

我遇到了一个问题。工具栏在iOS7 iphone 5s真机前添加内边距。

;

但是,在模拟器和 iOS7 iphone 4s 设备上都没有出现此问题。

我的配置是这样的

任何人都可以指出什么可能是错的?提前致谢

【问题讨论】:

    标签: ios iphone uitoolbar uisegmentedcontrol


    【解决方案1】:

    即使我也遇到了同样的问题(但是,在模拟器和设备中都看到了)。我使用setWidth 消息来限制每个段的宽度。所以,类似:-

    [segmentedControl setWidth:75.0f forSegmentAtIndex:0];
    

    应该可以解决这个问题。不过我没有使用故事板

    【讨论】:

      【解决方案2】:

      我并不为这个修复感到自豪,但它确实为我修复了它:

      // in the app delegate class
      #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
      
      // in the view
      - (void)fixToolbarWidth
      {
          if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
          {
              float adjust = -10.5f;
      
              // self.toolbar is linked to the UIToolbar
              self.toolbar.frame = CGRectMake(adjust, 0, [SizeHelper getSizeInOrientation].width-adjust, self.toolbar.frame.size.height);
      
              // self.segmentedControl is linked to the UISegmentedControl
              self.segmentedControl.frame = CGRectMake(0, 0, self.toolbar.frame.size.width+(adjust*2), self.segmentedControl.frame.size.height);
          }
      }
      - (void)viewDidLoad
      {
          [super viewDidLoad];
      
          // fix on first load
          [self fixToolbarWidth];
      }
      - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
      {
          [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
      
          // resize if they rotate the device
          [self fixToolbarWidth];
      }
      

      更新/更简单的版本

      只要您的工具栏和分段控制器正确设置为缩放 .xib 文件中的整个宽度,您就可以在 viewDidLoad 中执行以下操作

      if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
      {
          // use a different adjustment for iPad vs iPhone/touch
          float adjust = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? -14.0f : -9.0f;
          self.toolbar.frame = CGRectMake(adjust, 0, self.toolbar.frame.size.width-adjust, self.toolbar.frame.size.height);
          self.segmentedControl.frame = CGRectMake(0, 0, self.segmentedControl.frame.size.width+adjust, self.segmentedControl.frame.size.height);
      }
      

      【讨论】:

        【解决方案3】:

        我也有同样的问题。我所做的是将段控件从工具栏上移出。这对我有用。

        【讨论】:

          【解决方案4】:

          如果有人仍在寻找不包括固定段宽度的答案,您需要在UIToolbar 中的Segmented Control 周围使用Flexible Space

          【讨论】:

            猜你喜欢
            • 2013-11-25
            • 1970-01-01
            • 2014-07-24
            • 2014-01-27
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-10-22
            相关资源
            最近更新 更多