2015-10-04 83 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