iOS 6 UISegmentedControl采用iOS 7设计 [英] iOS 6 UISegmentedControl with iOS 7 design
本文介绍了iOS 6 UISegmentedControl采用iOS 7设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一款适用于iOS 6和iOS 7的应用程序,并且两者都采用相同的平面设计。
I'm working on an app that's supposed to work on both iOS 6 and iOS 7, and have the same flat design for both.
我正在尝试自定义我的UISegmentedControl有边框,角半径和所有,但我无法弄清楚如何这样做。到目前为止,我只能做一个平坦的背景。
I'm trying to customize my UISegmentedControl to have borders, corner radius and all, but I can't figure out how to do so. I've only mange to have a flat background so far.
有没有人有任何建议让iOS 6 UISegmentedControl看起来像iOS 7?
Does anyone have any advice to have an iOS 6 UISegmentedControl look like an iOS 7 one ?
编辑:
我想要
而不是
推荐答案
您可以使用以下代码:
// To set colour of text
NSDictionary *attributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
[segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
NSDictionary *highlightedAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
[segmentedControl setTitleTextAttributes:highlightedAttributes forState:UIControlStateHighlighted];
// Change color of selected segment
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
UIColor *newTintColor = [UIColor colorWithRed: 255/255.0 green:100/255.0 blue:100/255.0 alpha:1.0];
segmentedControl.tintColor = newTintColor;
UIColor *newSelectedTintColor = [UIColor clearColor];
[[[segmentedControl subviews] objectAtIndex:0] setTintColor:newSelectedTintColor];
对于设置圆角,您可以使用以下代码:
And for seting rounded corners you can use below code:
// Add rounded yellow corner to segmented controll view
[segmentedControl.layer setCornerRadius:4.0f];
[segmentedControl.layer setBorderColor:[UIColor colorWithRed:1.0 green:0.7 blue:0.14 alpha:1.0].CGColor];
[segmentedControl.layer setBorderWidth:1.5f];
[segmentedControl.layer setShadowColor:[UIColor blackColor].CGColor];
[segmentedControl.layer setShadowOpacity:0.8];
[segmentedControl.layer setShadowRadius:3.0];
[segmentedControl.layer setShadowOffset:CGSizeMake(2.0, 2.0)];
这篇关于iOS 6 UISegmentedControl采用iOS 7设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文