Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS 7中使用iOS 6样式的分段控件?_Ios_Ios6_Uisegmentedcontrol_Ios7 - Fatal编程技术网

在iOS 7中使用iOS 6样式的分段控件?

在iOS 7中使用iOS 6样式的分段控件?,ios,ios6,uisegmentedcontrol,ios7,Ios,Ios6,Uisegmentedcontrol,Ios7,iOS 7设备上的分段控件是否可能显示为该控件的iOS 6版本 我们还没有做好重新设计界面的准备,新的平面控件也没有与UI的其他部分协调。如果可能的话,现在最好还是保持iOS 6的风格 为了澄清,我正在使用iOS 6.1基本SDK进行编译。我知道这是我问题的“明显”答案,但它不起作用。通过这样做,大多数其他UI元素将在iOS 6样式中显示,但与UIAlertView和UIActionSheet一样,UISegmentedControl没有。但是,与UIAlertView和UIActionShee

iOS 7设备上的分段控件是否可能显示为该控件的iOS 6版本

我们还没有做好重新设计界面的准备,新的平面控件也没有与UI的其他部分协调。如果可能的话,现在最好还是保持iOS 6的风格

为了澄清,我正在使用iOS 6.1基本SDK进行编译。我知道这是我问题的“明显”答案,但它不起作用。通过这样做,大多数其他UI元素将在iOS 6样式中显示,但与
UIAlertView
UIActionSheet
一样,
UISegmentedControl
没有。但是,与
UIAlertView
UIActionSheet
不同,
UISegmentedControls
感觉不像是一个“系统”项目;它们应该能够在iOS 6模式下显示

编辑:我想如果我最终在其中加入一张图片会很有帮助(可能从一开始就应该这样做)。然而,我提供的答案确实解决了这个问题。此外,回想起来,它看起来可能是iOS 6的风格,毕竟,它只是显示得非常错误,看起来像iOS 7的风格

您可以:

  • 在您准备好进行一些UI更改之前,不要为iOS7更新您的应用程序。根据ios6sdk编译的应用程序将在iOS7上以iOS6兼容模式运行,并且看起来与在iOS6中完全相同
  • 将自定义背景、分隔符等图像应用到分段控件,以模仿它们在iOS6中的外观

    • 可能吗?不是真的

      您可以创建自己的自定义分段控件


      或者您可以使用
      UIAppearance
      代理来定制带有图像的分段控件,但您有责任使其看起来像是在iOS 6上的控件。

      是的,如果您自己重新创建控件,这是可能的。创建一个假分段控件,它看起来和工作起来都像一个。

      通过手动设置所有属性,我成功地解决了这个问题,但还不是很完美

      这就是我最后做的:

      - (void)fixSegmentedControlForiOS7
      {
          NSInteger deviceVersion = [[UIDevice currentDevice] systemVersion].integerValue;
          if(deviceVersion < 7) // If this is not an iOS 7 device, we do not need to perform these customizations.
              return;
      
          NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                      [UIFont boldSystemFontOfSize:12], UITextAttributeFont,
                                      [UIColor whiteColor], UITextAttributeTextColor,
                                      nil];
          [self.segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
          NSDictionary *highlightedAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
          [self.segmentedControl setTitleTextAttributes:highlightedAttributes forState:UIControlStateHighlighted];
      
          self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
          self.segmentedControl.tintColor = [UIColor colorWithRed:49.0 / 256.0 green:148.0 / 256.0 blue:208.0 / 256.0 alpha:1];
      }
      
      -(无效)IOS7的固定分段控件
      {
      NSInteger设备版本=[[UIDevice currentDevice]系统版本].integerValue;
      if(deviceVersion<7)//如果这不是iOS 7设备,我们不需要执行这些定制。
      返回;
      NSDictionary*属性=[NSDictionary Dictionary WithObjectsAndKeys:
      [UIFont boldSystemFontOfSize:12],UITextAttributeFont,
      [UIColor whiteColor],UITextAttributeTextColor,
      零];
      [self.segmentedControl setTitleTextAttributes:状态的属性:UIControlStateNormal];
      NSDictionary*HighlightedAttribute=[NSDictionary Dictionary WithObject:[UIColor whiteColor]forKey:UITextAttributeTextColor];
      [self.segmentedControl setTitleTextAttributes:高亮显示状态的属性:uicontrol状态高亮显示];
      self.segmentedControl.segmentedControlStyle=UISegmentedControlStyleBar;
      self.segmentedControl.tintColor=[uicolorWithred:49.0/256.0绿色:148.0/256.0蓝色:208.0/256.0 alpha:1];
      }
      
      如果您保存以前版本的XCode中的iPhoneOS6.1.sdk文件,并将其以相同的路径添加到XCode 5中,那么您可以针对6.1 sdk构建一个应用程序,这样当它在7上运行时,一切都像6。与ios7sdk的链接告诉iOS,如果可能的话,让一切看起来都像iOS7。基本上,您有一个iOS6应用程序,但使用XCode 5构建它。

      如果您在任何UISegmentedControl段上使用图像,您需要添加一些代码以在iOS 7上正确设置这些图像,否则它们将被用作模板图像,并且所选的段将是该段背景的剪影


      除非另有规定,否则iOS 7下的UISegmentedControl将其图像解释为处于呈现模式UIImageRenderingModeAlwaysTemplate。我必须在iOS 7的每个片段的图像上使用-[UIImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]来实现之前的行为。

      在我的应用程序中,我已将分段控件设置为“条形”样式。它在我的ios7 iphone5上以ios6风格呈现(哇,5,6,7)。但是,无论视图有多宽,段内的文本都会被剪切并添加三个点“…”。
      因此,ios7中的ios6分段控件呈现似乎真的有问题

      我今天自己也遇到了这个问题。我正在更新的应用程序非常旧,仍然使用xib文件,所以我不知道这是否适用于故事板。正如上面其他人所建议的,您仍然需要使用iOS 6.1 SDK,但仅此还不够。执行以下步骤后,我能够恢复旧的
      UISegmentedControl
      外观:

    • 打开有问题的interface builder文档
    • 转到文件检查器(第一个检查器选项卡;具有文档图标)
    • 在“Interface Builder文档”部分,将“Opens in”更改为Xcode 4.6
    • 我相信这是一个bug,如果在代码中创建的
      UISegmentedControl
      实例没有解决方法,我也不会感到惊讶。我猜这在某种程度上与iOS 7中对
      segmentedControlStyle
      属性的弃用有关(请参阅)


      希望这对其他人有所帮助。

      要修复使用InterfaceBuilder分配的图像,请使用以下代码:

      - (void)fixImagesOfSegmentedControlForiOS7
      {
          NSInteger deviceVersion = [[UIDevice currentDevice] systemVersion].integerValue;
          if(deviceVersion < 7) // If this is not an iOS 7 device, we do not need to perform these customizations.
              return;
      
          for(int i=0;i<toSegmentedControl.numberOfSegments;i++)
          {
              UIImage* img = [toSegmentedControl imageForSegmentAtIndex:i];
              UIImage* goodImg = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
              // clone image with different rendering mode
              [toSegmentedControl setImage:goodImg forSegmentAtIndex:i];
          }
      }
      
      -(void)修复IOS7分段控件的图像
      {
      NSInteger设备版本=[[UIDevice currentDevice]系统版本].integerValue;
      if(deviceVersion<7)//如果这不是iOS 7设备,我们不需要执行这些定制。
      返回;
      
      对于(int i=0;我不能用iOS 6 SDK编译吗?你可能会这么认为,但这不起作用…这确实解决了其他iOS 7 UI类型的问题,但没有解决分段控件的问题。不知道为什么它不起作用。听起来像是个bug。你应该在几乎任何时候都能看到iOS 6的外观