Hi all, I wanted to create a shadowed UINavigationBar with rounded corners. I
know alot of people do this with images, but I wanted to see if I could find
a 'all code solution'

I have successfully done this:
http://dl.dropbox.com/u/10852937/monotouch/ShadowRoundedNavigationBar1.png 
but I've run into a small problem. When I add a LeftBarButton Item (and/or
RightBarButton) the buttons don't press - unless you press ~10 pixels under
the buttons. I presume changing the CoreGraphics layer size (to add the
shadow) has upset something in UIKit, but I'm at a loss now how to fix. 

A sample project can be found here:

http://dl.dropbox.com/u/10852937/monotouch/UINavigationBarTest.zip

and the code in question is:

public class RoundedShadowedUINavigationController : UINavigationController
{
        public override void ViewDidLoad ()
        {
                base.ViewDidLoad ();
                NavigationBar.TintColor = UIColor.FromRGB (0.231f, 0.349f, 
0.596f);
                DrawShadowedRoundedNavigationBar ();                    
        }
                
        public override void DidRotate (UIInterfaceOrientation
fromInterfaceOrientation)
        {
                base.DidRotate (fromInterfaceOrientation);
                DrawShadowedRoundedNavigationBar ();
        }
                
        private void DrawShadowedRoundedNavigationBar ()
        {                       
                NavigationBar.Layer.ShadowColor = UIColor.Black.CGColor;        
                        
                NavigationBar.Layer.ShadowOpacity = 0.85f;
                NavigationBar.Layer.ShadowOffset = new SizeF (0.0f, 1.5f);
                NavigationBar.Layer.ShadowRadius = 2.0f;
                NavigationBar.Layer.ShouldRasterize = true;     
                var bounds = NavigationBar.Layer.Bounds;
                bounds.Size = new SizeF (bounds.Size.Width, bounds.Size.Height 
+ 10);
                var maskPath = UIBezierPath.FromRoundedRect (
                        bounds,
                        UIRectCorner.TopLeft | UIRectCorner.TopRight,
                        new SizeF (5, 5)
                );
                var masklayer = new CAShapeLayer ();
                masklayer.Frame = bounds;
                masklayer.Path = maskPath.CGPath;
                NavigationBar.Layer.AddSublayer (masklayer);
                NavigationBar.Layer.Mask = masklayer;
        }
}

If anyone has any pointers that would be great.

Thanks

Andy

--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/Rounded-UINavigation-Controller-with-Shadow-problem-tp4620040.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to