2015-10-04 82 views
0

我有颜色全部设为我希望他们用这种方式:调整范围条的圆形cornors在UISearchController酒吧

// Scope bar appearance 
[[UISegmentedControl appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor blueColor]]; 
[[UISegmentedControl appearanceWhenContainedIn: [UISearchBar class], nil] setBackgroundColor:[UIColor whiteColor]]; 

但我仍然得到白色透进来并且不是圆的。

见图片:

enter image description here

我该如何解决这个问题?谢谢。

+0

我不想白色作为一个非圆边 – cdub

回答

0

在你的appdelegate顶部

@interface UISegmentedControl (Appearance) 

- (void)setCornerRadius:(CGFloat)cornerRadius UI_APPEARANCE_SELECTOR; 


@end 

@implementation UISegmentedControl (Appearance) 

- (void)setCornerRadius:(CGFloat)cornerRadius { 
    self.layer.cornerRadius = cornerRadius; 
} 


@end 

添加该代码,然后你可以在didFinishLaunchingWithOptions

[[UISegmentedControl appearanceWhenContainedIn: [UISearchBar class], nil] setCornerRadius:5]; 
+0

我有这个,但其不能在我的ios 8实例中工作 – cdub

+0

您可以在您尝试过的地方张贴代码吗? – Imran

+0

我从我的文章直接在我的代码下有您的代码。它在isMemberOfClass – cdub

0

请试试这个:

segmentContrl.layer.borderColor = <Set_Your_Color>; 
segmentContrl.layer.cornerRadius = 0.5; // You might have to adjust this 
segmentContrl.layer.borderWidth = 1.5f; // You might have to adjust this 
+0

不知怎的,使用上述第一个答案抓住这使边框围绕整个搜索栏控制器的子视图,而不是范围吧 – cdub

0

试试下面调用添加以下代码代码设置cornerRadius后。

segmentContrl.clipsToBounds = true