-
Notifications
You must be signed in to change notification settings - Fork 2
/
Utility.cs
54 lines (49 loc) · 1.54 KB
/
Utility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using CoreGraphics;
using UIKit;
namespace iOSMaterialShowcase.Xamarin
{
public class Utility
{
}
public static class UIViewExtension
{
public static void AsCircle(this UIView _view)
{
_view.Layer.CornerRadius = _view.Frame.Width * .5f;
_view.Layer.MasksToBounds = true;
}
public static void SetTintColor(this UIView _view, UIColor _color, bool _recursive)
{
if (_recursive)
{
_view.TintColor = _color;
foreach (var view in _view.Subviews)
view.SetTintColor(_color, true);
}
else
_view.TintColor = _color;
}
}
public static class CGRectExtension
{
public static CGPoint Center(this CGRect _rect)
{
return new CGPoint(_rect.GetMidX(), _rect.GetMidY());
}
}
public static class UILabelExtension
{
public static void SizeToFitHeight(this UILabel _label)
{
UILabel tempLabel = new UILabel(new CGRect(0, 0, _label.Frame.Width, float.MaxValue))
{
Lines = _label.Lines,
LineBreakMode = _label.LineBreakMode,
Font = _label.Font,
Text = _label.Text
};
tempLabel.SizeToFit();
_label.Frame = new CGRect(_label.Frame.GetMinX(), _label.Frame.GetMinY(), _label.Frame.Width, tempLabel.Frame.Height);
}
}
}