本文整理汇总了C#中UIView.AddConstraint方法的典型用法代码示例。如果您正苦于以下问题:C# UIView.AddConstraint方法的具体用法?C# UIView.AddConstraint怎么用?C# UIView.AddConstraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIView
的用法示例。
在下文中一共展示了UIView.AddConstraint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad();
var view = new UIView
{
BackgroundColor = UIColor.White
};
var label = new UILabel
{
TranslatesAutoresizingMaskIntoConstraints = false,
Text = "No Conversation Selected",
TextColor = UIColor.FromWhiteAlpha(0.0f, 0.4f),
Font = UIFont.PreferredHeadline
};
view.AddSubview(label);
view.AddConstraint(NSLayoutConstraint.Create(label, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal,
view, NSLayoutAttribute.CenterX, 1.0f, 0.0f));
view.AddConstraint(NSLayoutConstraint.Create(label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal,
view, NSLayoutAttribute.CenterY, 1.0f, 0.0f));
View = view;
}
示例2: SetRelativeHeight
/// <summary>
/// STATCODE_CA1709
/// </summary>
public static NSLayoutConstraint SetRelativeHeight(UIView ancestor, UIView outer, UIView inner, nfloat ratio)
{
if (ancestor != null)
{
NSLayoutConstraint constraint = NSLayoutConstraint.Create
(
inner,
NSLayoutAttribute.Height,
NSLayoutRelation.Equal,
outer,
NSLayoutAttribute.Height,
ratio,
0
);
ancestor.AddConstraint(constraint);
return constraint;
}
return null;
}
示例3: SetHeight
public static NSLayoutConstraint SetHeight(UIView target, nfloat height)
{
if (target != null)
{
NSLayoutConstraint constraint = NSLayoutConstraint.Create
(
target,
NSLayoutAttribute.Height,
NSLayoutRelation.Equal,
null,
NSLayoutAttribute.NoAttribute,
1,
height
);
target.AddConstraint(constraint);
return constraint;
}
return null;
}
示例4: SetWidth
public static NSLayoutConstraint SetWidth(UIView target, nfloat width)
{
if (target != null)
{
NSLayoutConstraint constraint = NSLayoutConstraint.Create
(
target,
NSLayoutAttribute.Width,
NSLayoutRelation.Equal,
null,
NSLayoutAttribute.NoAttribute,
1,
width
);
target.AddConstraint(constraint);
return constraint;
}
return null;
}
示例5: AddViews
void AddViews()
{
if (toolbar == null) {
toolbar = new UIToolbar();
View.AddSubview(toolbar);
toolbar.TranslatesAutoresizingMaskIntoConstraints = false;
View.AddConstraint(NSLayoutConstraint.Create(toolbar, NSLayoutAttribute.LeadingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(toolbar, NSLayoutAttribute.TrailingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Trailing, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(toolbar, NSLayoutAttribute.BottomMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(toolbar, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.Height, 1, 44));
}
if (webView == null) {
webView = new CustomWebView();
View.AddSubview(webView);
webView.TranslatesAutoresizingMaskIntoConstraints = false;
View.AddConstraint(NSLayoutConstraint.Create(webView, NSLayoutAttribute.LeadingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(webView, NSLayoutAttribute.TrailingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Trailing, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(webView, NSLayoutAttribute.BottomMargin, NSLayoutRelation.Equal, toolbar, NSLayoutAttribute.Top, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(webView, NSLayoutAttribute.TopMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, 0));
}
if (activityView == null) {
activityView = new UIView();
activityView.Hidden = true;
activityView.BackgroundColor = UIColor.Black.ColorWithAlpha(0.2f);
View.AddSubview(activityView);
activityView.TranslatesAutoresizingMaskIntoConstraints = false;
View.AddConstraint(NSLayoutConstraint.Create(activityView, NSLayoutAttribute.LeadingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(activityView, NSLayoutAttribute.TrailingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Trailing, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(activityView, NSLayoutAttribute.BottomMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(activityView, NSLayoutAttribute.TopMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, 0));
UIActivityIndicatorView indicator = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge);
indicator.StartAnimating();
activityView.AddSubview(indicator);
indicator.TranslatesAutoresizingMaskIntoConstraints = false;
activityView.AddConstraint(NSLayoutConstraint.Create(indicator, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, activityView, NSLayoutAttribute.CenterX, 1, 0));
activityView.AddConstraint(NSLayoutConstraint.Create(indicator, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, activityView, NSLayoutAttribute.CenterY, 1, 0));
//activityView.AddConstraint(NSLayoutConstraint.Create(indicator, NSLayoutAttribute.Width, NSLayoutRelation.Equal, indicator, NSLayoutAttribute.Width, 1, 80));
//activityView.AddConstraint(NSLayoutConstraint.Create(indicator, NSLayoutAttribute.Height, NSLayoutRelation.Equal, indicator, NSLayoutAttribute.Height, 1, 80));
}
}
示例6: CreateNickNameView
void CreateNickNameView()
{
titleContainer = new UIView (new CGRect(0, 0, 200, 20));
nickNameLbl = new UILabel {
TranslatesAutoresizingMaskIntoConstraints = false,
TextAlignment = UITextAlignment.Center,
};
nickNameEditIcon = new UIImageView {
TranslatesAutoresizingMaskIntoConstraints = false,
Image = UIImage.FromBundle ("editNickName"),
};
nickNameInput = new UITextField {
TranslatesAutoresizingMaskIntoConstraints = false,
ShouldReturn = ShouldReturn,
TextAlignment = UITextAlignment.Center,
BorderStyle = UITextBorderStyle.RoundedRect,
BackgroundColor = UIColor.White,
};
nickNameInput.Ended += NickNameEditingEnded;
titleContainer.AddSubviews (nickNameLbl, nickNameInput, nickNameEditIcon);
Center(nickNameLbl);
titleContainer.AddConstraint (PlaceOnTheRight (nickNameLbl, nickNameEditIcon, 10));
CenterVertically (nickNameEditIcon);
PinLeftRightEdges (nickNameInput);
CenterVertically (nickNameInput);
tap = new UITapGestureRecognizer (StartEditNickName) {
NumberOfTapsRequired = 1
};
titleContainer.AddGestureRecognizer (tap);
ShowNormalNickNameVisualState ();
}
示例7: SetConstant
NSLayoutConstraint SetConstant(UIView view, NSLayoutAttribute attr, nfloat value)
{
var c = NSLayoutConstraint.Create (view, attr, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 0, value);
view.AddConstraint (c);
return c;
}
示例8: FollowControlVertically
public static NSLayoutConstraint FollowControlVertically(UIView ancestor, UIView first, UIView next, nfloat margin)
{
if (ancestor != null)
{
NSLayoutConstraint constraint = NSLayoutConstraint.Create
(
next,
NSLayoutAttribute.Top,
NSLayoutRelation.Equal,
first,
NSLayoutAttribute.Bottom,
1,
margin
);
ancestor.AddConstraint(constraint);
return constraint;
}
return null;
}
示例9: SetRelativeWidth
public static NSLayoutConstraint SetRelativeWidth(UIView ancestor, UIView outer, UIView inner, nfloat ratio)
{
NSLayoutConstraint constraint = NSLayoutConstraint.Create
(
inner,
NSLayoutAttribute.Width,
NSLayoutRelation.Equal,
outer,
NSLayoutAttribute.Width,
ratio,
0
);
ancestor.AddConstraint(constraint);
return constraint;
}
示例10: AttachToParentBottom
public static NSLayoutConstraint AttachToParentBottom(UIView parent, UIView child, nfloat margin)
{
if (parent != null)
{
NSLayoutConstraint constraint = NSLayoutConstraint.Create
(
parent,
NSLayoutAttribute.Bottom,
NSLayoutRelation.Equal,
child,
NSLayoutAttribute.Bottom,
1,
margin
);
parent.AddConstraint(constraint);
return constraint;
}
return null;
}
示例11: AlignCentersVertically
public static NSLayoutConstraint AlignCentersVertically(UIView ancestor, UIView fixedControl, UIView controlToCenter)
{
NSLayoutConstraint constraint = NSLayoutConstraint.Create
(
controlToCenter,
NSLayoutAttribute.CenterY,
NSLayoutRelation.Equal,
fixedControl,
NSLayoutAttribute.CenterY,
1,
0
);
ancestor.AddConstraint(constraint);
return constraint;
}
示例12:
public static NSLayoutConstraint AlignTops
(
UIView ancestor,
UIView fixedControl,
UIView controlToAlign
)
{
NSLayoutConstraint constraint = NSLayoutConstraint.Create
(
controlToAlign,
NSLayoutAttribute.Top,
NSLayoutRelation.Equal,
fixedControl,
NSLayoutAttribute.Top,
1,
0
);
ancestor.AddConstraint(constraint);
return constraint;
}
示例13: CenterControlVertically
public static NSLayoutConstraint CenterControlVertically(UIView outer, UIView inner)
{
if (outer != null)
{
NSLayoutConstraint constraint = NSLayoutConstraint.Create
(
inner,
NSLayoutAttribute.CenterY,
NSLayoutRelation.Equal,
outer,
NSLayoutAttribute.CenterY,
1,
0
);
outer.AddConstraint(constraint);
return constraint;
}
return null;
}
示例14: FollowControlHorizontally
public static NSLayoutConstraint FollowControlHorizontally(UIView ancestor, UIView first, UIView next, nfloat margin)
{
NSLayoutConstraint constraint = NSLayoutConstraint.Create
(
next,
NSLayoutAttribute.Left,
NSLayoutRelation.Equal,
first,
NSLayoutAttribute.Right,
1,
margin
);
ancestor.AddConstraint(constraint);
return constraint;
}
示例15: LoadView
public override void LoadView ()
{
UIView view = new UIView ();
UIButton newButton = UIButton.FromType (UIButtonType.System);
newButton.TranslatesAutoresizingMaskIntoConstraints = false;
newButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
newButton.SetTitle ("New Game", UIControlState.Normal);
newButton.TitleLabel.Font = UIFont.PreferredBody;
newButton.TouchUpInside += newGame;
view.AddSubview (newButton);
UIButton pauseButton = UIButton.FromType (UIButtonType.System);
pauseButton.TranslatesAutoresizingMaskIntoConstraints = false;
pauseButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
pauseButton.SetTitle ("Pause", UIControlState.Normal);
pauseButton.TitleLabel.Font = UIFont.PreferredBody;
pauseButton.TouchUpInside += togglePause;
view.AddSubview (pauseButton);
gameView = new TTTGameView () {
ImageForPlayer = ImageForPlayer,
ColorForPlayer = ColorForPlayer,
CanSelect = CanSelect,
DidSelect = DidSelect,
TranslatesAutoresizingMaskIntoConstraints = false,
Game = Profile.CurrentGame
};
view.AddSubview (gameView);
float topHeight = UIApplication.SharedApplication.StatusBarFrame.Size.Height;
UITabBar tabBar = TabBarController.TabBar;
float bottomHeight = tabBar.Translucent ? tabBar.Frame.Size.Height : 0;
NSDictionary metrics = NSDictionary.FromObjectsAndKeys (
new NSNumber[] { new NSNumber (topHeight + ControllerMargin),
new NSNumber (bottomHeight + ControllerMargin),
new NSNumber (ControllerMargin)
},
new NSString[] { new NSString ("topHeight"), new NSString ("bottomHeight"),
new NSString ("margin")
}
);
NSDictionary bindings = NSDictionary.FromObjectsAndKeys (
new NSObject[] { newButton, pauseButton, gameView },
new NSString [] {
new NSString ("newButton"), new NSString ("pauseButton"),
new NSString ("gameView")
}
);
view.AddConstraints (NSLayoutConstraint.FromVisualFormat (
"|-margin-[gameView]-margin-|", (NSLayoutFormatOptions)0,
metrics, bindings
));
view.AddConstraints (NSLayoutConstraint.FromVisualFormat (
"|-margin-[pauseButton(==newButton)]-[newButton]-margin-|",
(NSLayoutFormatOptions)0, metrics, bindings
));
view.AddConstraints (NSLayoutConstraint.FromVisualFormat (
"V:|-topHeight-[gameView]-margin-[newButton]-bottomHeight-|",
(NSLayoutFormatOptions)0, metrics, bindings
));
view.AddConstraint (NSLayoutConstraint.Create (pauseButton,
NSLayoutAttribute.Baseline,
NSLayoutRelation.Equal,
newButton,
NSLayoutAttribute.Baseline,
1f,
0f));
View = view;
}