Hi,

I have this Monotouch.Dialog app with UITableViewStyle.Plain that uses a
custom header:

        root.Add(
                new Section{
                        HeaderView = new CustomHeader
                        });

I need the custom header while I need to position the text at computed
coordinates:

namespace MySpace
{
        private const float _height = 23f;
        public class CustomHeader : UIView
        {
                private string _title;
                public CustomHeader(string title) : base(new RectangleF(0f, 0f,
                        UIScreen.MainScreen.ApplicationFrame.Width, _height))
                {
                        _title = title;
                }

                public override void Draw(RectangleF rectangle)
                {
                        UIColor.LightGray.SetFill();
                        var context = UIGraphics.GetCurrentContext();
                        context.FillRect(rectangle);
                        UIColor.Black.SetColor();
                        // define variables x, y, width, height,
                        // and then draw the text
                        DrawString(_title, new RectangleF(x, y, width, height),
                                MyConfig.BoldFont, 
UILineBreakMode.TailTruncation);
                }
        }
}

But I want to use a background image.

First idea was to base my CustomHeader on UIImageView rather than
UIView:

namespace MySpace
{
        private const float _height = 23f;
        public class CustomHeader : UIImageView
        {
                private string _title;
                public CustomHeader(string title) : base(new RectangleF(0f, 0f,
                        UIScreen.MainScreen.ApplicationFrame.Width, _height))
                {
                        _title = title;
                        BackGroundColor = UIColor.Clear;
                        Image = UIImage.FromFile("Image.png");
                }

                public override void Draw(RectangleF rectangle)
                {
                        ...
                }
        }
}

This shows the background, but without text as the Draw method is no
longer called.

Then I tried to stick with the UIView, and add an UIImageView:

namespace MySpace
{
        private const float _height = 23f;
        public class CustomHeader : UIView
        {
                private string _title;
                public CustomHeader(string title) : base(new RectangleF(0f, 0f,
                        UIScreen.MainScreen.ApplicationFrame.Width, _height))
                {
                        _title = title;
                        BackGroundColor = UIColor.Clear;
                var bg = new UIImageView {
                                Frame = new RectangleF(0f, 0f,
                                        
UIScreen.MainScreen.ApplicationFrame.Width, Height),
                    BackgroundColor = UIColor.Clear,
                    Image =
UIImage.FromFile("Images/TableViewPlainHeaderBackground.png")
                };
                        AddSubView(bg);
                        SendSubviewToBack(bg);
                }

                public override void Draw(RectangleF rectangle)
                {
                        ...
                }
        }
}

This approach also shows the image, but no text.

I have the distinct feeling that this should be fairly simple, but
apparently I need some help here.

Thanks in advance,


Guido

--
You need only reflect that one of the best ways to get yourself a
reputation as a dangerous citizen these days is to go about repeating
the very phrases which our founding fathers used in the struggle for
independence.
                -- Charles A. Beard
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to