【问题标题】:Adjusting the rounded cornors of a scope bar in an UISearchController bar在 UISearchController 栏中调整范围栏的圆角
【发布时间】:2015-10-16 21:54:01
【问题描述】:

我已经按照我想要的方式设置了颜色:

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

但我仍然可以看到白色,而不是四舍五入。

看图:

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

【问题讨论】:

  • 我不希望白色作为非圆角边缘

标签: ios ios8 uisearchbar uisegmentedcontrol uisearchcontroller


【解决方案1】:

在你的 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];

【讨论】:

  • 我有这个,但它在我的 ios 8 实例中不起作用
  • 我的帖子中的代码直接位于您的代码下方。它在 isMemberOfClass 上失败
  • 我的 for 是:for (id subview in self.searchController.searchBar.subviews)
  • 是的,它在我的 viewDidLoad 中,它是一个包含 UISearchController 属性的视图控制器
  • for循环有一个视图作为子视图:它是UIView
【解决方案2】:

请试试这个:

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

【讨论】:

  • 不知何故使用上面的第一个答案来抓取子视图,这会在整个搜索栏控制器而不是范围栏周围设置一个边框
【解决方案3】:

设置cornerRadius后尝试调用下面的代码。

segmentContrl.clipsToBounds = true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    相关资源
    最近更新 更多