Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

UISegmentedControl in UIToolbar

$
0
0

Hello!

I've been experimenting with displaying an UISegmentedControl at the bottom of a screen in the NavigationControllers UIToolbar, but I haven't had any success so far. The code below is what some people believe should be working on Objective-C, and I've tried to translate it to C#, see my code below the first block.

Original Objective-C code:

UIBarButtonItem *segItem = [[UIBarButtonItem alloc] initWithCustomView:navSC];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];
[toolBar setItems:[NSArray arrayWithObjects:spaceItem,segItem,spaceItem,nil] animated:YES];
[segItem release];
[spaceItem release];

My translated C# code:

var types = new [] {
    MonoTouch.Foundation.NSBundle.MainBundle.LocalizedString ("SMB_marathon", "Segmented button marathon"),
    MonoTouch.Foundation.NSBundle.MainBundle.LocalizedString ("SMB_relay", "Segmented button relay")
};
bottomSwitcher = new UISegmentedControl (types) {
    SelectedSegment = 0,
    AutoresizingMask = UIViewAutoresizing.FlexibleWidth,
};
bottomSwitcher.BackgroundColor = UIColor.FromRGB (242, 245, 245);
bottomSwitcher.TintColor = UIColor.FromRGB (0, 175, 180);
var segmentedButton = new UIBarButtonItem();
segmentedButton.CustomView = bottomSwitcher;
this.NavigationController.Toolbar.SetItems (new UIBarButtonItem[]{ segmentedButton }, true);

Has anyone in this forum achieved this before, or can you spot what is wrong with my code? The code compiles properly, but nothing is shown in the UIToolbar.

Thanks in advance, Jonathan


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>