Permalink
Browse files

New controls

  • Loading branch information...
RobertKozak committed Feb 5, 2012
1 parent fd1b22f commit 8db8abccc0fe61698925e02a9b662a01e38209f4
Showing with 212 additions and 0 deletions.
  1. +114 −0 Controls/UIBorderedView.cs
  2. +96 −0 Controls/VerticalAlignmentLabel.cs
  3. +2 −0 MonoMobile.Views.csproj
View
@@ -0,0 +1,114 @@
+//
+// UIBorderedView.cs
+//
+// Author:
+// Robert Kozak (rkozak@gmail.com / Twitter:@robertkozak)
+//
+// Copyright 2011 - 2012, Nowcom Corporation.
+//
+// Code licensed under the MIT X11 license
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+namespace MonoMobile.Views
+{
+ using System;
+ using MonoTouch.UIKit;
+ using System.Drawing;
+
+ public partial class UIBorderedView : UIView
+ {
+ private UIActivityIndicatorView _ActivityIndicatorView;
+
+ public int CornerRadius { get; set; }
+ public UIColor ShadowColor { get; set; }
+ public float ShadowOpacity { get; set; }
+ public float ShadowRadius { get; set; }
+ public SizeF ShadowOffset { get; set; }
+ public int BorderWidth { get; set; }
+
+ public UIBorderedView(IntPtr handle) : base(handle)
+ {
+ Initialize();
+ CreateCurveAndShadow();
+ }
+
+ public UIBorderedView(RectangleF frame) : base(frame)
+ {
+ Initialize();
+ CreateCurveAndShadow();
+ }
+
+ public void AddImage(UIImage image, bool animate)
+ {
+ if (image != null)
+ {
+ InvokeOnMainThread(() =>
+ {
+ var bounds = Bounds;
+ var imageView = new UIImageView(new RectangleF(BorderWidth, BorderWidth, Bounds.Width - (BorderWidth * 2), Bounds.Height - (BorderWidth * 2)));
+ imageView.Layer.CornerRadius = 5.0f;
+ imageView.Layer.MasksToBounds = true;
+ imageView.Layer.BorderWidth = 1;
+ imageView.Layer.BorderColor = UIColor.LightGray.CGColor;
+ imageView.Image = image;
+ imageView.Alpha = 0f;
+
+ Add(imageView);
+
+ _ActivityIndicatorView.StopAnimating();
+
+ UIView.BeginAnimations("fadeIn");
+ UIView.SetAnimationDuration(animate ? 0.6f : 0f);
+ imageView.Alpha = 1.0f;
+ UIView.CommitAnimations();
+ });
+ }
+ }
+
+ private void Initialize()
+ {
+ _ActivityIndicatorView = new UIActivityIndicatorView(Bounds);
+ _ActivityIndicatorView.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray;
+ _ActivityIndicatorView.HidesWhenStopped = true;
+ _ActivityIndicatorView.StartAnimating();
+
+ Add(_ActivityIndicatorView);
+
+ CornerRadius = 10;
+ ShadowColor = UIColor.DarkGray;
+ ShadowOpacity = 1.0f;
+ ShadowRadius = 1.0f;
+ ShadowOffset = new SizeF(0, 0);
+ BackgroundColor = UIColor.White;
+ }
+
+ private void CreateCurveAndShadow()
+ {
+ Layer.MasksToBounds = false;
+ Layer.ShadowColor = ShadowColor.CGColor;
+ Layer.ShadowOpacity = ShadowOpacity;
+ Layer.ShadowRadius = ShadowRadius;
+ Layer.ShadowOffset = ShadowOffset;
+ Layer.CornerRadius = CornerRadius;
+ }
+ }
+}
+
@@ -0,0 +1,96 @@
+//
+// VerticalAlignmnentLabel.cs
+//
+// Author:
+// Robert Kozak (rkozak@gmail.com / Twitter:@robertkozak)
+//
+// Copyright 2011 - 2012, Nowcom Corporation.
+//
+// Code licensed under the MIT X11 license
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+namespace MonoMobile.Views
+{
+ using System.Drawing;
+ using MonoTouch.UIKit;
+
+ public enum UIVerticalAlignment
+ {
+ Middle = 0, //the default (what standard UILabels do)
+ Top,
+ Bottom
+ }
+
+ public class VerticalAlignmnentLabel : UILabel
+ {
+ private UIVerticalAlignment _VerticalAlignment;
+
+ public UIVerticalAlignment VerticalAlignment
+ {
+ get { return _VerticalAlignment; }
+ set
+ {
+ if (_VerticalAlignment != value)
+ {
+ _VerticalAlignment = value;
+ SetNeedsDisplay();
+ }
+ }
+ }
+
+ public VerticalAlignmnentLabel()
+ {
+ }
+
+ public VerticalAlignmnentLabel(RectangleF rect) : base(rect)
+ {
+ }
+
+ public override void DrawText(RectangleF rect)
+ {
+ RectangleF bounds = TextRectForBounds(rect, Lines);
+
+ base.DrawText(bounds);
+ }
+
+ public override RectangleF TextRectForBounds(RectangleF bounds, int numberOfLines)
+ {
+ RectangleF calculatedRect = base.TextRectForBounds(bounds, numberOfLines);
+
+ if (_VerticalAlignment != UIVerticalAlignment.Top)
+ {
+ if (_VerticalAlignment == UIVerticalAlignment.Bottom)
+ {
+ bounds.Y += bounds.Height - calculatedRect.Height; //move down by difference
+ }
+ else
+ {
+ bounds.Y += (bounds.Height - calculatedRect.Height) / 2;
+ }
+ }
+
+ bounds.Height = calculatedRect.Height; //always the calculated height
+
+ return (bounds);
+ }
+ }
+}
+
View
@@ -264,6 +264,8 @@
<Compile Include="Application\ActionResult.cs" />
<Compile Include="Interfaces\ISelectableInterceptor.cs" />
<Compile Include="Interfaces\ICommandInterceptor.cs" />
+ <Compile Include="Controls\VerticalAlignmentLabel.cs" />
+ <Compile Include="Controls\UIBorderedView.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Images\" />

0 comments on commit 8db8abc

Please sign in to comment.