2014-09-27 56 views
0

有谁知道如何使UISegmentedControl透明?我设置了ViewController的背景主题和文本颜色。我目前正在使用此代码ViewDidLoad如何使UISegmentedcontrol变得透明?

segGame.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.4]; 

有什么办法来设置segmentedControl编程或厦门国际银行的?

回答

0

您必须制作自定义段控制器。

将此代码写入您的ViewDidLoad方法。没问题

请试试这个:

// Set set segmentControl background to transparent 

CGRect rect = CGRectMake(0, 0, 1, 1); 
UIGraphicsBeginImageContext(rect.size); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]); 
CGContextFillRect(context, rect); 
UIImage *transparentImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

[segmentControl setBackgroundImage:transparentImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
[segmentControl setDividerImage:transparentImage forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

如果使用图像这一块,那么它看起来比背景透明度

[segmentControl setDividerImage:[UIImage new] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
    [segmentControl setBackgroundImage:[UIImage new] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

更好试试这一个。

+0

有没有什么办法可以在xib中设置segmentedControl透明? – 2014-09-27 11:19:16

+0

点击此链接:http://www.framewreck.net/2010/07/custom-tintcolor-for-each-segment-of.html – 2014-09-27 12:17:33

+1

xib它已经与透明。哪个xcode你使用? – 2014-09-27 12:19:05

0

You can choose any colour for background in storyboard

故事板是你想做的事非常方便。看看screnshot。