Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

New controls

  • Loading branch information...
commit 8db8abccc0fe61698925e02a9b662a01e38209f4 1 parent fd1b22f
Robert Kozak authored
114  Controls/UIBorderedView.cs
... ...
@@ -0,0 +1,114 @@
  1
+// 
  2
+//  UIBorderedView.cs
  3
+// 
  4
+//  Author:
  5
+//    Robert Kozak (rkozak@gmail.com / Twitter:@robertkozak)
  6
+// 
  7
+//  Copyright 2011 - 2012, Nowcom Corporation.
  8
+// 
  9
+//  Code licensed under the MIT X11 license
  10
+// 
  11
+//  Permission is hereby granted, free of charge, to any person obtaining
  12
+//  a copy of this software and associated documentation files (the
  13
+//  "Software"), to deal in the Software without restriction, including
  14
+//  without limitation the rights to use, copy, modify, merge, publish,
  15
+//  distribute, sublicense, and/or sell copies of the Software, and to
  16
+//  permit persons to whom the Software is furnished to do so, subject to
  17
+//  the following conditions:
  18
+// 
  19
+//  The above copyright notice and this permission notice shall be
  20
+//  included in all copies or substantial portions of the Software.
  21
+// 
  22
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23
+//  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24
+//  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25
+//  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26
+//  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27
+//  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28
+//  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29
+// 
  30
+namespace MonoMobile.Views
  31
+{
  32
+	using System;
  33
+	using MonoTouch.UIKit;
  34
+	using System.Drawing;
  35
+
  36
+	public partial class UIBorderedView : UIView
  37
+	{
  38
+		private UIActivityIndicatorView _ActivityIndicatorView;
  39
+
  40
+		public int CornerRadius { get; set; }
  41
+		public UIColor ShadowColor { get; set; }
  42
+		public float ShadowOpacity { get; set; }
  43
+		public float ShadowRadius { get; set; }
  44
+		public SizeF ShadowOffset { get; set; }
  45
+		public int BorderWidth { get; set; }
  46
+
  47
+		public UIBorderedView(IntPtr handle) : base(handle)
  48
+		{
  49
+			Initialize();
  50
+			CreateCurveAndShadow();
  51
+		}
  52
+
  53
+		public UIBorderedView(RectangleF frame) : base(frame)
  54
+		{
  55
+			Initialize();
  56
+			CreateCurveAndShadow();
  57
+		}
  58
+		
  59
+		public void AddImage(UIImage image, bool animate)
  60
+		{
  61
+			if (image != null)
  62
+			{
  63
+				InvokeOnMainThread(() =>
  64
+				{
  65
+					var bounds = Bounds;
  66
+					var imageView = new UIImageView(new RectangleF(BorderWidth, BorderWidth, Bounds.Width - (BorderWidth * 2), Bounds.Height - (BorderWidth * 2)));
  67
+					imageView.Layer.CornerRadius = 5.0f;
  68
+					imageView.Layer.MasksToBounds = true;
  69
+					imageView.Layer.BorderWidth = 1;
  70
+					imageView.Layer.BorderColor = UIColor.LightGray.CGColor;
  71
+					imageView.Image = image;
  72
+					imageView.Alpha = 0f;
  73
+	
  74
+					Add(imageView);
  75
+				
  76
+					_ActivityIndicatorView.StopAnimating();
  77
+
  78
+					UIView.BeginAnimations("fadeIn");
  79
+					UIView.SetAnimationDuration(animate ? 0.6f : 0f);
  80
+					imageView.Alpha = 1.0f;
  81
+					UIView.CommitAnimations();
  82
+				});
  83
+			}
  84
+		}
  85
+
  86
+		private void Initialize()
  87
+		{
  88
+			_ActivityIndicatorView = new UIActivityIndicatorView(Bounds);
  89
+			_ActivityIndicatorView.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray;
  90
+			_ActivityIndicatorView.HidesWhenStopped = true;
  91
+			_ActivityIndicatorView.StartAnimating();
  92
+
  93
+			Add(_ActivityIndicatorView);
  94
+
  95
+			CornerRadius = 10;
  96
+			ShadowColor = UIColor.DarkGray;
  97
+			ShadowOpacity = 1.0f;
  98
+			ShadowRadius = 1.0f;
  99
+			ShadowOffset = new SizeF(0, 0);
  100
+			BackgroundColor = UIColor.White;
  101
+		}
  102
+
  103
+		private void CreateCurveAndShadow()
  104
+		{
  105
+			Layer.MasksToBounds = false;
  106
+			Layer.ShadowColor = ShadowColor.CGColor;
  107
+			Layer.ShadowOpacity = ShadowOpacity;
  108
+			Layer.ShadowRadius = ShadowRadius;
  109
+			Layer.ShadowOffset = ShadowOffset; 	
  110
+			Layer.CornerRadius = CornerRadius;	
  111
+		}
  112
+	}
  113
+}
  114
+
96  Controls/VerticalAlignmentLabel.cs
... ...
@@ -0,0 +1,96 @@
  1
+// 
  2
+//  VerticalAlignmnentLabel.cs
  3
+// 
  4
+//  Author:
  5
+//    Robert Kozak (rkozak@gmail.com / Twitter:@robertkozak)
  6
+// 
  7
+//  Copyright 2011 - 2012, Nowcom Corporation.
  8
+// 
  9
+//  Code licensed under the MIT X11 license
  10
+// 
  11
+//  Permission is hereby granted, free of charge, to any person obtaining
  12
+//  a copy of this software and associated documentation files (the
  13
+//  "Software"), to deal in the Software without restriction, including
  14
+//  without limitation the rights to use, copy, modify, merge, publish,
  15
+//  distribute, sublicense, and/or sell copies of the Software, and to
  16
+//  permit persons to whom the Software is furnished to do so, subject to
  17
+//  the following conditions:
  18
+// 
  19
+//  The above copyright notice and this permission notice shall be
  20
+//  included in all copies or substantial portions of the Software.
  21
+// 
  22
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23
+//  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24
+//  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25
+//  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26
+//  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27
+//  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28
+//  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29
+// 
  30
+namespace MonoMobile.Views
  31
+{
  32
+	using System.Drawing;
  33
+	using MonoTouch.UIKit;
  34
+
  35
+	public enum UIVerticalAlignment
  36
+	{ 
  37
+		Middle = 0,    //the default (what standard UILabels do) 
  38
+		Top,
  39
+		Bottom
  40
+	} 
  41
+
  42
+	public class VerticalAlignmnentLabel : UILabel
  43
+	{ 
  44
+		private UIVerticalAlignment _VerticalAlignment;
  45
+
  46
+		public UIVerticalAlignment VerticalAlignment
  47
+		{ 
  48
+			get { return _VerticalAlignment; } 
  49
+			set
  50
+			{ 
  51
+				if (_VerticalAlignment != value)
  52
+				{ 
  53
+					_VerticalAlignment = value; 
  54
+					SetNeedsDisplay();   
  55
+				} 
  56
+			} 
  57
+		} 
  58
+
  59
+		public VerticalAlignmnentLabel()
  60
+		{
  61
+		}
  62
+
  63
+		public VerticalAlignmnentLabel(RectangleF rect) : base(rect)
  64
+		{
  65
+		} 
  66
+
  67
+		public override void DrawText(RectangleF rect)
  68
+		{ 
  69
+			RectangleF bounds = TextRectForBounds(rect, Lines); 
  70
+
  71
+			base.DrawText(bounds); 
  72
+		} 
  73
+
  74
+		public override RectangleF TextRectForBounds(RectangleF bounds, int numberOfLines)
  75
+		{
  76
+			RectangleF calculatedRect = base.TextRectForBounds(bounds, numberOfLines);
  77
+ 
  78
+			if (_VerticalAlignment != UIVerticalAlignment.Top)
  79
+			{   
  80
+				if (_VerticalAlignment == UIVerticalAlignment.Bottom)
  81
+				{ 
  82
+					bounds.Y += bounds.Height - calculatedRect.Height;    //move down by difference
  83
+				}
  84
+				else
  85
+				{    
  86
+					bounds.Y += (bounds.Height - calculatedRect.Height) / 2; 
  87
+				} 
  88
+			} 
  89
+
  90
+			bounds.Height = calculatedRect.Height;    //always the calculated height 
  91
+
  92
+			return (bounds); 
  93
+		} 
  94
+	}
  95
+}
  96
+
2  MonoMobile.Views.csproj
@@ -264,6 +264,8 @@
264 264
     <Compile Include="Application\ActionResult.cs" />
265 265
     <Compile Include="Interfaces\ISelectableInterceptor.cs" />
266 266
     <Compile Include="Interfaces\ICommandInterceptor.cs" />
  267
+    <Compile Include="Controls\VerticalAlignmentLabel.cs" />
  268
+    <Compile Include="Controls\UIBorderedView.cs" />
267 269
   </ItemGroup>
268 270
   <ItemGroup>
269 271
     <Folder Include="Images\" />

0 notes on commit 8db8abc

Please sign in to comment.
Something went wrong with that request. Please try again.