I'm still playing with different button and navigation options to see how
things work and what will work for my needs. Today I'm working with a
UIToolBar at the bottom of my main view. Following what I've read in various
examples, I wrote the following, which works in that the bar and the buttons
display and you can click 'em and they launch the new view as intended. The
problem is that I want to use images for the buttons, and the images are not
displaying (I can get them to display as custom UIBottons but not as
UIBarButtons). Here's what I've got so far:
toolbar = new UIToolbar (new RectangleF (0
, toolbarVert
, this.View.Frame.Width,
toolbarHeight));
// 1st toolbar button: Map Regions
UIBarButtonItem regionsTBB = new UIBarButtonItem (UIImage.FromFile
("images/regionsButton.png"), UIBarButtonItemStyle.Plain, Action);
// 2nd toobar button: Mail TBB
UIBarButtonItem mailTBB = new UIBarButtonItem (UIImage.FromFile
("images/mailButton.png"), UIBarButtonItemStyle.Plain, Action);
// 3rd toobar button: TBB Website
UIBarButtonItem websiteTBB = new UIBarButtonItem (UIImage.FromFile
("images/websitButton.png"), UIBarButtonItemStyle.Plain, Action);
// 4th toolbar button: Help
UIBarButtonItem helpTBB = new UIBarButtonItem (UIImage.FromFile
("images/helpButton.png"), UIBarButtonItemStyle.Plain, Action);
// create the items array
UIBarButtonItem[] items = new UIBarButtonItem[] {
regionsTBB, mailTBB, websiteTBB, helpTBB };
// add the items to the toolbar
toolbar.SetItems (items, true);
this.View.AddSubview (toolbar);
(Action is an event handling method.)
Like I said, so far everything here works as intended except that the
buttons are not displaying the images as intended. The code compiles without
error or warnings.
I'm guessing that the UIBarButtonItemStyle.Plain part is overriding the
UIImage.FromFile part (maybe?), but every UIBarButtonItem constructor that
includes UIImage.FromFile requires a UIBarButtonItemStyle as the second
argument. The three options listed in the API are Plain, Bordered, and Done.
I've tried all three just to see, and the image doesn't display as the
button for any of them.
What am I doing wrong? How do I get the UIImage.FromFile thing to work with
these UIBarButtonItems?
My second question is about positioning buttons on the toolbar. Are there
any options other than using the Flexible and Fixed Space bar button items?
--Chris
--
View this message in context:
http://monotouch.2284126.n4.nabble.com/UIToolBar-Button-Question-tp4655537.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch