segmentedControl 和 UIAppearance 代理的图形问题

发布于 2025-01-05 08:02:44 字数 2621 浏览 1 评论 0原文

我有一个应用程序,标题栏中有一个分段控件,用于在 3 个导航控制器之间切换。我正在使用新的外观代理方法来设置此segmentedControl 的样式(代码如下)。然而,似乎有某种我无法弄清楚的错误。当我潜入其中一个导航控制器然后导航回根目录(然后再次在顶部栏中显示分段控件)时,它就会出现。当这种情况发生时,分隔线图形就会变得混乱,正如您在屏幕截图中看到的那样(第一个显示了它应该是什么样子)。

有没有人遇到过类似的情况并知道如何解决?

我设置外观的代码是:

  UIImage *segmentSelected            = [[UIImage imageNamed:@"sel"]      resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
UIImage *segmentUnselected          = [[UIImage imageNamed:@"uns"]      resizableImageWithCapInsets:UIEdgeInsetsMake(0, 3, 0, 3)];
UIImage *segmentSelectedUnselected  = [[UIImage imageNamed:@"sel-uns"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
UIImage *segUnselectedSelected      = [[UIImage imageNamed:@"uns-sel"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
UIImage *segmentUnselectedUnselected = [[UIImage imageNamed:@"uns-uns"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];

[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setBackgroundImage:segmentUnselected forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setBackgroundImage:segmentSelected forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setDividerImage:segmentUnselectedUnselected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setDividerImage:segmentSelectedUnselected forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setDividerImage:segUnselectedSelected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setContentPositionAdjustment:UIOffsetMake(8, 0) forSegmentType:UISegmentedControlSegmentLeft barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setContentPositionAdjustment:UIOffsetMake(-8, 0) forSegmentType:UISegmentedControlSegmentRight barMetrics:UIBarMetricsDefault];

它应该是什么样子:

它应该是什么样子

它看起来像什么例如:

在此处输入图像描述

I have an app with a segmentedControl in the titleBar, which is used to switch between 3 navigation controllers. I am using the new appearence proxy methods to style this segmentedControl (code below). However, there seems to be some sort of bug that I cannot figure out. It appears when I dive into one of the navigation controllers and then navigate back to the root (which then shows the segmentedControl in the top bar again). When that happens the divider graphics get messed up as you can see in the screenshot (the first one shows what it's supposed to look like).

Has anyone encountered anything similar and knows how to fix it?

My code to set the appearence is:

  UIImage *segmentSelected            = [[UIImage imageNamed:@"sel"]      resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
UIImage *segmentUnselected          = [[UIImage imageNamed:@"uns"]      resizableImageWithCapInsets:UIEdgeInsetsMake(0, 3, 0, 3)];
UIImage *segmentSelectedUnselected  = [[UIImage imageNamed:@"sel-uns"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
UIImage *segUnselectedSelected      = [[UIImage imageNamed:@"uns-sel"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
UIImage *segmentUnselectedUnselected = [[UIImage imageNamed:@"uns-uns"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];

[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setBackgroundImage:segmentUnselected forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setBackgroundImage:segmentSelected forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setDividerImage:segmentUnselectedUnselected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setDividerImage:segmentSelectedUnselected forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setDividerImage:segUnselectedSelected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setContentPositionAdjustment:UIOffsetMake(8, 0) forSegmentType:UISegmentedControlSegmentLeft barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setContentPositionAdjustment:UIOffsetMake(-8, 0) forSegmentType:UISegmentedControlSegmentRight barMetrics:UIBarMetricsDefault];

what it is supposed to look like:

what it is supposed to look like

what it looks like:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少女七分熟 2025-01-12 08:02:44

我通过外观使用了 UINavigatorBar 的背景图像,并注意到将该方法与 UISplitViewController/UIPopoverController 一起使用,整个导航栏被移入内容区域。所以你只看到深蓝色边框,定制的导航栏位于边框的正下方,看起来很奇怪。

对你没有帮助,但这可能是一个真正的错误?!

I've used a backgroundImage for UINavigatorBar via appearance and noticed that using that approach together with a UISplitViewController/UIPopoverController the whole navigation bar is moved into the content area. So you just see the darkblue border and the customized Navigation bar is positioned right below the border looking very strange.

No help for you but it might be a real bug?!

太阳男子 2025-01-12 08:02:44

我也遇到过同样的问题。最终我最终使用了 1px 宽的分隔符图像 ->然后问题就消失了。

I've had the same issue. Eventually I ended up using a 1px wide divider image -> then the issue disappeared.

纵情客 2025-01-12 08:02:44

请确保您在应用程序委托 didfinishLaunching 中使用它应用于所有视图控制器。我有同样的问题图像重叠。在一个地方使用它解决了问题。尝试使用 [uiview class] 而不是 [uinavigationBar class]

Please make sure you are using this in app delegate didfinishLaunching applied for all the view controller.I have the same problem image overlapped . use it in one place problem resolved .Try with [uiview class] instead of [uinavigationBar class]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文