-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodedViewController.cs
More file actions
119 lines (99 loc) · 4.5 KB
/
CodedViewController.cs
File metadata and controls
119 lines (99 loc) · 4.5 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using UIKit;
namespace AutoLayoutConstraints
{
public class CodedViewController : UIViewController
{
private UILabel titleLabel;
private UIImageView plusImage;
private UILabel text1Label;
private UILabel text2Label;
private UILabel text3Label;
private UIButton button;
private UISlider slider;
public CodedViewController()
{
TabBarItem.Title = "Coded";
TabBarItem.Image = UIImage.FromBundle("Square");
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
View.BackgroundColor = UIColor.White;
titleLabel = new UILabel
{
TranslatesAutoresizingMaskIntoConstraints = false,
Text = "Title",
Font = UIFont.PreferredTitle1,
TextAlignment = UITextAlignment.Center,
};
plusImage = new UIImageView
{
TranslatesAutoresizingMaskIntoConstraints = false,
Image = UIImage.FromBundle("Plus"),
ContentMode = UIViewContentMode.ScaleAspectFit,
};
text1Label = new UILabel
{
TranslatesAutoresizingMaskIntoConstraints = false,
Text = "Subtitle",
Font = UIFont.PreferredTitle2,
TextAlignment = UITextAlignment.Left,
};
text2Label = new UILabel
{
TranslatesAutoresizingMaskIntoConstraints = false,
Text = "Very long text",
Font = UIFont.PreferredBody,
TextAlignment = UITextAlignment.Left,
};
text3Label = new UILabel
{
TranslatesAutoresizingMaskIntoConstraints = false,
Text = "Text",
Font = UIFont.PreferredFootnote,
TextAlignment = UITextAlignment.Left,
};
button = new UIButton(UIButtonType.RoundedRect)
{
TranslatesAutoresizingMaskIntoConstraints = false,
BackgroundColor = UIColor.LightGray,
};
button.SetTitle("Button", UIControlState.Normal);
slider = new UISlider
{
TranslatesAutoresizingMaskIntoConstraints = false,
MinValue = 0,
MaxValue = 1,
Value = 0.5f,
};
View.AddSubviews(titleLabel, plusImage, text1Label, text2Label, text3Label, button, slider);
var guide = View.SafeAreaLayoutGuide;
NSLayoutConstraint.ActivateConstraints(new[]
{
titleLabel.TopAnchor.ConstraintEqualTo(guide.TopAnchor, 16),
titleLabel.LeadingAnchor.ConstraintEqualTo(guide.LeadingAnchor, 8),
titleLabel.TrailingAnchor.ConstraintEqualTo(guide.TrailingAnchor, -8),
plusImage.TopAnchor.ConstraintEqualTo(titleLabel.BottomAnchor, 16),
plusImage.LeadingAnchor.ConstraintEqualTo(guide.LeadingAnchor, 8),
plusImage.WidthAnchor.ConstraintEqualTo(40),
plusImage.BottomAnchor.ConstraintEqualTo(slider.BottomAnchor),
text1Label.LeadingAnchor.ConstraintEqualTo(plusImage.TrailingAnchor, 16),
text2Label.LeadingAnchor.ConstraintEqualTo(plusImage.TrailingAnchor, 16),
text3Label.LeadingAnchor.ConstraintEqualTo(plusImage.TrailingAnchor, 16),
text1Label.TopAnchor.ConstraintEqualTo(plusImage.TopAnchor),
text2Label.TopAnchor.ConstraintEqualTo(text1Label.BottomAnchor, 8),
text3Label.TopAnchor.ConstraintEqualTo(text2Label.BottomAnchor, 8),
button.LeadingAnchor.ConstraintGreaterThanOrEqualTo(text1Label.TrailingAnchor, 16),
button.LeadingAnchor.ConstraintGreaterThanOrEqualTo(text2Label.TrailingAnchor, 16),
button.LeadingAnchor.ConstraintGreaterThanOrEqualTo(text3Label.TrailingAnchor, 16),
button.WidthAnchor.ConstraintGreaterThanOrEqualTo(60),
button.TopAnchor.ConstraintEqualTo(text1Label.TopAnchor),
button.BottomAnchor.ConstraintEqualTo(text3Label.BottomAnchor),
slider.TopAnchor.ConstraintEqualTo(text3Label.BottomAnchor, 8),
slider.LeadingAnchor.ConstraintEqualTo(text1Label.LeadingAnchor),
slider.TrailingAnchor.ConstraintEqualTo(button.TrailingAnchor),
});
}
}
}