调整 UISearchController 栏中范围栏的圆角
Adjusting the rounded cornors of a scope bar in an UISearchController bar
我已经按照我想要的方式设置了颜色:
// Scope bar appearance
[[UISegmentedControl appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor blueColor]];
[[UISegmentedControl appearanceWhenContainedIn: [UISearchBar class], nil] setBackgroundColor:[UIColor whiteColor]];
但我仍然看到白色没有变圆。
见图:
我该如何解决这个问题?谢谢
请试试这个:
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
在您的 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];
设置cornerRadius后尝试调用下面的代码。
segmentContrl.clipsToBounds = true
我已经按照我想要的方式设置了颜色:
// Scope bar appearance
[[UISegmentedControl appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor blueColor]];
[[UISegmentedControl appearanceWhenContainedIn: [UISearchBar class], nil] setBackgroundColor:[UIColor whiteColor]];
但我仍然看到白色没有变圆。
见图:
我该如何解决这个问题?谢谢
请试试这个:
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
在您的 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];
设置cornerRadius后尝试调用下面的代码。
segmentContrl.clipsToBounds = true