UISegmentedControl 仅显示设备上的第一项,但在模拟器中工作

发布于 2024-11-26 18:16:58 字数 1053 浏览 1 评论 0原文

我已经搜索了如何将 UISegmentedControl 项目添加到导航栏按钮项目(右栏按钮)。它在模拟器中工作正常,但当我在设备上尝试它时,仅显示分段控件中的第一项。它占据了整个长度(即整个事物中只有一个片段)。

- (void) setupSegmentedControl {
//set up the segmented control and add it to the nav bar rightBartButtonItem
UISegmentedControl * segmentControl = [[UISegmentedControl alloc] initWithItems:[NSArray         arrayWithObjects:[UIImage imageNamed:@"Settings.png"],[UIImage imageNamed:@"Map-Icon.png"],[UIImage imageNamed:@"Search.png"], nil]];
UIBarButtonItem * segmentControlButton = [[UIBarButtonItem alloc] initWithCustomView:segmentControl];
[segmentControl setBackgroundColor:[UIColor clearColor]];
segmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentControl.frame = CGRectMake(0, 0, 75, 30);
[segmentControl setMomentary:YES];
[segmentControl addTarget:self
                   action:@selector(segmentedControlAction:)
         forControlEvents:UIControlEventValueChanged];
self.navigationItem.rightBarButtonItem = segmentControlButton;
[segmentControl release];

}

有什么想法出了什么问题吗?

I have searched around an figured out how to add a UISegmentedControl item to the navigation bar button item (right bar button). It works fine in the simulator but when I try it on the device, only the first item in the segmented control shows up. It occupies the full length (i.e. there is only one segment across the whole thing).

- (void) setupSegmentedControl {
//set up the segmented control and add it to the nav bar rightBartButtonItem
UISegmentedControl * segmentControl = [[UISegmentedControl alloc] initWithItems:[NSArray         arrayWithObjects:[UIImage imageNamed:@"Settings.png"],[UIImage imageNamed:@"Map-Icon.png"],[UIImage imageNamed:@"Search.png"], nil]];
UIBarButtonItem * segmentControlButton = [[UIBarButtonItem alloc] initWithCustomView:segmentControl];
[segmentControl setBackgroundColor:[UIColor clearColor]];
segmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentControl.frame = CGRectMake(0, 0, 75, 30);
[segmentControl setMomentary:YES];
[segmentControl addTarget:self
                   action:@selector(segmentedControlAction:)
         forControlEvents:UIControlEventValueChanged];
self.navigationItem.rightBarButtonItem = segmentControlButton;
[segmentControl release];

}

Any ideas what going wrong?

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

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

发布评论

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

评论(1

夜还是长夜 2024-12-03 18:16:58

确保图像文件名与项目中的资源名称完全匹配,包括大写/小写字母。

设备区分大小写,如果名称不匹配,imageNamed: 将返回 nil 终止数组。

Make sure that the image filenames match exactly with the resource names in your project including uppercase/lowercase letters.

The device is case-sensitive and if the name doesn't match, imageNamed: will return nil terminating the array.

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