在iOS 7中使用iOS 6 Style Segmented Control? [英] Use iOS 6 Style Segmented Control in iOS 7?

查看:75
本文介绍了在iOS 7中使用iOS 6 Style Segmented Control?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在iOS 7设备上显示分段控件作为控件的iOS 6版本?

Is it possible to have a segmented control on an iOS 7 device show up as the iOS 6 version of the control?

我们还没准备好界面重新设计和新的平面控件与我们的UI的其余部分不相符。如果可能的话,现在最好保留iOS 6风格。

We really aren't ready for an interface redesign and the new flat control doesn't jive with the rest of our UI. It would definitely be best to keep the iOS 6 style for now, if possible.

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

To clarify, I am compiling using the iOS 6.1 Base SDK. I am aware that this is the "obvious" answer to my question, but it does not work. Most other UI elements will show up with iOS 6 styling by doing this, but like the UIAlertView and UIActionSheet, the UISegmentedControl does not. However, unlike the UIAlertView and UIActionSheet, UISegmentedControls do not feel like a "system" item; they should be able to display in iOS 6 mode.

编辑:我认为如果我最终包含一张图片(可能应该从开始)。但是,我提供的答案确实解决了这个问题。此外,回想起来,看起来可能毕竟是iOS 6风格,它只是显示错误,看起来像iOS 7风格。

I thought it would be helpful if I finally included a picture with this (probably should have done this from the start). However, the answer I provided did fix the issue. Also, in retrospect, it looks like this might be the iOS 6 style after all, it's just displaying so wrong that it appears like iOS 7 style.

推荐答案

我设法通过手动设置所有属性来很好地解决这个问题,但它并不完美。

I manage to do a pretty good job of solving this problem by setting all the attributes manually, but it is not quite perfect.

这个是我最终做的:

- (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];
}

这篇关于在iOS 7中使用iOS 6 Style Segmented Control?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆