是否可以将iOS 7设备上的分段控件显示为iOS 6版本的控件?
我们真的还没有准备好重新设计界面,新的平面控件与我们UI的其余部分并不协调。如果可能的话,现在最好还是保留iOS 6的风格。
为了清楚起见,我使用iOS 6.1Base SDK进行编译。我知道这是我的问题的“显而易见的”答案,但它不起作用。通过这样做,大多数其他UI元素将在iOS 6样式中显示,但像UIAlertView
和UIActionSheet
一样,UISegmentedControl
不会。但是,与UIAlertView
和UIActionSheet
不同的是,UISegmentedControls
不像是一个“系统”项;它们应该能够在iOS 6模式下显示。
编辑:我认为如果我最终在这篇文章中加入一张图片会很有帮助(可能从一开始就应该这样做)。然而,我提供的答案确实解决了这个问题。此外,回想起来,这款可能毕竟是iOS 6的风格,它只是显示错误,看起来像iOS 7的风格。
发布于 2013-09-20 02:13:07
通过手动设置所有属性,我设法很好地解决了这个问题,但它并不是很完美。
这就是我最终要做的:
- (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];
}
发布于 2013-09-27 19:47:54
要修复使用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];
}
}
发布于 2013-09-24 05:51:15
今天我自己也遇到了这个问题。我正在更新的应用程序很旧,仍然使用xib文件,所以我不知道这在故事板上是否有效。正如其他人所建议的那样,您仍然需要使用iOS 6.1SDK,但仅有这一点是不够的。执行以下步骤后,我能够恢复原来的UISegmentedControl
外观:
我确实认为这是一个错误,如果在代码中创建的UISegmentedControl
实例没有解决方法,我也不会感到惊讶。我猜这在某种程度上与iOS 7中segmentedControlStyle
属性的弃用有关(请参阅https://developer.apple.com/library/ios/documentation/uikit/reference/UISegmentedControl_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instp/UISegmentedControl/segmentedControlStyle)。
希望这能对外面的人有所帮助。
https://stackoverflow.com/questions/18900034
复制相似问题