开发者

UISegmentedControl only shows first item on device but works in Simulator

开发者 https://www.devze.com 2023-03-23 07:22 出处:网络
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

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 clearColo开发者_运维问答r]];
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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消