Mik*_*keS 15 uisegmentedcontrol ios ios6 ios7
iOS 7设备上的分段控件是否可以显示为iOS 6版本的控件?
我们还没有为接口重新设计做好准备,而新的平板控制与其他用户界面并不相符.如果可能的话,现在最好保留iOS 6风格.
为了澄清,我正在使用iOS 6.1 Base SDK进行编译.我知道这是我问题的"明显"答案,但它不起作用.大多数其他UI元素将通过这样做显示iOS 6样式,但是像UIAlertView
和UIActionSheet
,而UISegmentedControl
不是.但是,不像UIAlertView
和UIActionSheet
,UISegmentedControls
不喜欢"系统"项目; 他们应该能够在iOS 6模式下显示.
编辑:我认为如果我最终包含一张图片(可能应该从一开始就做到这一点)会有所帮助.但是,我提供的答案确实解决了这个问题.另外,回想起来,看起来这可能是iOS 6风格,它只是显示错误,看起来像iOS 7风格.
Mik*_*keS 20
我设法通过手动设置所有属性来很好地解决这个问题,但它并不完美.
这就是我最终做的事情:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
cat*_*cat 13
要修复使用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];
}
}
Run Code Online (Sandbox Code Playgroud)
我今天刚遇到这个问题.我正在进行更新的应用程序已经很老了,仍然使用xib文件,所以我不知道这是否适用于故事板.正如上面其他人所建议的那样,你仍然需要使用iOS 6.1 SDK,但仅凭这一点还不够.执行以下步骤后,我能够恢复旧的UISegmentedControl
外观:
我确实认为这是一个错误,如果没有UISegmentedControl
在代码中创建的实例的解决方法,我不会感到惊讶.我猜这与segmentedControlStyle
iOS 7 中的属性弃用有些相关(参见https://developer.apple.com/library/ios/documentation/uikit/reference/UISegmentedControl_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instp/UISegmentedControl/segmentedControlStyle).
希望这有助于那里的人.