Fonts with Autolayout

SteveStewardSteveSteward USUniversity ✭✭

I have what appears to be a very simple problem. I cannot change the size of a font when using autoLayout programmatically. See the code below. No matter what I do, I cannot seem to set the font size. If I remove "TranslatesAutoresizingMaskIntoConstraints", it works fine. Everything else works great. I just cannot change the size of the font. I've tried everything and I cannot find any good documentation on how to hand code autoLayout elements. I know I gotta be missing something minor.

Any help would be appreciated!

var time = (DateTime.Now.Minute > 30) ? DateTime.Now.AddMinutes(30-DateTime.Now.Minute) : DateTime.Now.AddMinutes(-DateTime.Now.Minute);
var date = new UILabel() {
  Font = UIFont.FromName("Arial-MT", 50),
  TextColor = UIColor.White,
  Text = time.ToString("ddd MM/dd h:mmt"),
  TextAlignment = UITextAlignment.Center,
  Layer = {
    ShadowColor = UIColor.Black.CGColor,
    ShadowOffset = new CGSize(0, 1),
    ShadowOpacity = 0.5f,
    ShadowRadius = 0
date.TranslatesAutoresizingMaskIntoConstraints = false;
guideHeader.AddConstraint(NSLayoutConstraint.Create(date, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, guideHeader, NSLayoutAttribute.CenterX, 1, 0));
guideHeader.AddConstraint(NSLayoutConstraint.Create(date, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, guideHeader, NSLayoutAttribute.CenterY, 1, 0));
guideHeader.AddConstraint(NSLayoutConstraint.Create(date, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.Height, 1, 10));
guideHeader.AddConstraint(NSLayoutConstraint.Create(date, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.Width, 1, 250)); 
Sign In or Register to comment.