在 iOS 7 中使用 iOS 6 样式分段控件? [英] Use iOS 6 Style Segmented Control in iOS 7?

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

问题描述

是否可以将 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 样式,但与 UIAlertViewUIActionSheet 一样,UISegmentedControl 不会.然而,与UIAlertViewUIActionSheet 不同的是,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 样式分段控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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