Skip to content

Commit a5aa9d0

Browse files
committed
Added HeaderedTextBlock control for Android and iOS.
1 parent a358368 commit a5aa9d0

15 files changed

Lines changed: 892 additions & 3 deletions

MADE.App.Design/Color/Color.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace MADE.App.Design.Color
1111
{
12+
using System.Globalization;
13+
1214
/// <summary>
1315
/// Defines a model for a UI element color.
1416
/// </summary>
@@ -37,6 +39,33 @@ internal Color(byte a, byte r, byte g, byte b)
3739
this.B = b;
3840
}
3941

42+
/// <summary>
43+
/// Initializes a new instance of the <see cref="Color"/> class.
44+
/// </summary>
45+
/// <param name="hexValue">
46+
/// The ARGB or RGB hex value represented as a string.
47+
/// </param>
48+
public Color(string hexValue)
49+
{
50+
string val = hexValue.ToUpper();
51+
52+
switch (val.Length)
53+
{
54+
case 7:
55+
this.A = 255;
56+
this.R = byte.Parse(val.Substring(1, 2), NumberStyles.AllowHexSpecifier);
57+
this.G = byte.Parse(val.Substring(3, 2), NumberStyles.AllowHexSpecifier);
58+
this.B = byte.Parse(val.Substring(5, 2), NumberStyles.AllowHexSpecifier);
59+
break;
60+
case 9:
61+
this.A = byte.Parse(val.Substring(1, 2), NumberStyles.AllowHexSpecifier);
62+
this.R = byte.Parse(val.Substring(3, 2), NumberStyles.AllowHexSpecifier);
63+
this.G = byte.Parse(val.Substring(5, 2), NumberStyles.AllowHexSpecifier);
64+
this.B = byte.Parse(val.Substring(7, 2), NumberStyles.AllowHexSpecifier);
65+
break;
66+
}
67+
}
68+
4069
#if WINDOWS_UWP || __ANDROID__
4170
/// <summary>
4271
/// Initializes a new instance of the <see cref="Color"/> class with a <see cref="System.Drawing.Color"/>.
@@ -186,7 +215,7 @@ public Color(UIKit.UIColor color)
186215
{
187216
if (color.CGColor.NumberOfComponents == 2)
188217
{
189-
var rgb = (byte)(color.CGColor.Components[0] * 255);
218+
byte rgb = (byte)(color.CGColor.Components[0] * 255);
190219
this.R = rgb;
191220
this.G = rgb;
192221
this.B = rgb;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="BaseStyle.iOS.cs" company="MADE Apps">
3+
// Copyright (c) MADE Apps.
4+
// </copyright>
5+
// <summary>
6+
// Defines a base class for creating styles that can be applied to iOS UIView elements.
7+
// </summary>
8+
// --------------------------------------------------------------------------------------------------------------------
9+
10+
#if __IOS__
11+
namespace MADE.App.Design.Styles
12+
{
13+
using MADE.App.Design.Color;
14+
15+
using UIKit;
16+
17+
/// <summary>
18+
/// Defines a base class for creating styles that can be applied to iOS <see cref="UIView"/> elements.
19+
/// </summary>
20+
/// <typeparam name="TView">
21+
/// The type of <see cref="UIView"/> to apply the style to.
22+
/// </typeparam>
23+
public abstract class BaseStyle<TView> where TView : UIView
24+
{
25+
/// <summary>
26+
/// Gets or sets the level of alpha transparency for the view from 0 to 1.
27+
/// </summary>
28+
public float? Opacity { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the background color of the view.
32+
/// </summary>
33+
public Color BackgroundColor { get; set; }
34+
35+
/// <summary>
36+
/// Applies the properties of the style to the given <see cref="UIView"/>.
37+
/// </summary>
38+
/// <param name="view">
39+
/// The view to apply the style to.
40+
/// </param>
41+
public virtual void Apply(TView view)
42+
{
43+
if (view == null)
44+
{
45+
return;
46+
}
47+
48+
if (this.BackgroundColor != null)
49+
{
50+
view.BackgroundColor = this.BackgroundColor;
51+
}
52+
53+
if (this.Opacity != null && this.Opacity >= 0.0 && this.Opacity <= 1.0)
54+
{
55+
view.Alpha = (System.nfloat)this.Opacity;
56+
}
57+
}
58+
}
59+
}
60+
#endif
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="UILabelStyle.cs" company="MADE Apps">
3+
// Copyright (c) MADE Apps.
4+
// </copyright>
5+
// <summary>
6+
// Defines the style model for an iOS UILabel.
7+
// </summary>
8+
// --------------------------------------------------------------------------------------------------------------------
9+
10+
#if __IOS__
11+
namespace MADE.App.Design.Styles
12+
{
13+
using MADE.App.Design.Color;
14+
15+
using UIKit;
16+
17+
/// <summary>
18+
/// Defines the style model for an iOS <see cref="UILabel"/>.
19+
/// </summary>
20+
public class UILabelStyle : BaseStyle<UILabel>
21+
{
22+
/// <summary>
23+
/// Gets or sets the foreground color (color of the text) of the view.
24+
/// </summary>
25+
public Color ForegroundColor { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets the alignment of the text in the view.
29+
/// </summary>
30+
public UITextAlignment TextAlignment { get; set; }
31+
32+
/// <summary>
33+
/// Applies the properties of the style to the given <see cref="UILabel"/>.
34+
/// </summary>
35+
/// <param name="view">
36+
/// The view to apply the style to.
37+
/// </param>
38+
public override void Apply(UILabel view)
39+
{
40+
base.Apply(view);
41+
42+
if (this.ForegroundColor != null)
43+
{
44+
view.TextColor = this.ForegroundColor;
45+
}
46+
47+
view.TextAlignment = this.TextAlignment;
48+
}
49+
}
50+
}
51+
#endif

0 commit comments

Comments
 (0)