UISegmentedControl 仅显示设备上的第一项,但在模拟器中工作
我已经搜索了如何将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保图像文件名与项目中的资源名称完全匹配,包括大写/小写字母。
设备区分大小写,如果名称不匹配,
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 returnnil
terminating the array.