Exemple #1
0
        public static MGTransform TransformAttribute(MGAttribute attr, float val)
        {
            MGTransform a = new MGTransform();

            a.Attribute = attr;
            a.Value     = val;
            a.Curve     = MGTransformCurve.Linear;

            return(a);
        }
Exemple #2
0
        private void SetAttribute(MGTransform attr, UIView view, nfloat thisRatio, Dictionary <string, NSLayoutConstraint> cs, Dictionary <string, nfloat> cvals)
        {
            switch (attr.Attribute)
            {
            case MGAttribute.X:

                if (cs.ContainsKey(NSLayoutAttribute.Leading.ToString()))
                {
                    UpdateConstraint(cs[NSLayoutAttribute.Leading.ToString()], cvals[NSLayoutAttribute.Leading.ToString()], attr, thisRatio);
                }

                if (cs.ContainsKey(NSLayoutAttribute.LeadingMargin.ToString()))
                {
                    UpdateConstraint(cs[NSLayoutAttribute.LeadingMargin.ToString()], cvals[NSLayoutAttribute.LeadingMargin.ToString()], attr, thisRatio);
                }

                if (cs.ContainsKey(NSLayoutAttribute.Trailing.ToString()))
                {
                    UpdateConstraint(cs[NSLayoutAttribute.Trailing.ToString()], cvals[NSLayoutAttribute.Trailing.ToString()], attr, thisRatio);
                }

                if (cs.ContainsKey(NSLayoutAttribute.TrailingMargin.ToString()))
                {
                    UpdateConstraint(cs[NSLayoutAttribute.TrailingMargin.ToString()], cvals[NSLayoutAttribute.TrailingMargin.ToString()], attr, thisRatio);
                }

                break;

            case MGAttribute.Y:

                if (cs.ContainsKey(NSLayoutAttribute.Top.ToString()))
                {
                    UpdateConstraint(cs[NSLayoutAttribute.Top.ToString()], cvals[NSLayoutAttribute.Top.ToString()], attr, thisRatio);
                }

                if (cs.ContainsKey(NSLayoutAttribute.TopMargin.ToString()))
                {
                    UpdateConstraint(cs[NSLayoutAttribute.TopMargin.ToString()], cvals[NSLayoutAttribute.TopMargin.ToString()], attr, thisRatio);
                }

                if (cs.ContainsKey(NSLayoutAttribute.Bottom.ToString()))
                {
                    UpdateConstraint(cs[NSLayoutAttribute.Bottom.ToString()], cvals[NSLayoutAttribute.Bottom.ToString()], attr, thisRatio);
                }

                if (cs.ContainsKey(NSLayoutAttribute.BottomMargin.ToString()))
                {
                    UpdateConstraint(cs[NSLayoutAttribute.BottomMargin.ToString()], cvals[NSLayoutAttribute.BottomMargin.ToString()], attr, thisRatio);
                }

                break;

            case MGAttribute.Width:

                if (cs.ContainsKey(NSLayoutAttribute.Width.ToString()))
                {
                    UpdateConstraint(cs[NSLayoutAttribute.Width.ToString()], cvals[NSLayoutAttribute.Width.ToString()], attr, thisRatio);
                }

                break;

            case MGAttribute.Height:

                if (cs.ContainsKey(NSLayoutAttribute.Height.ToString()))
                {
                    UpdateConstraint(cs[NSLayoutAttribute.Height.ToString()], cvals[NSLayoutAttribute.Height.ToString()], attr, thisRatio);
                }

                break;

            case MGAttribute.CornerRadius:
                view.Layer.CornerRadius = attr.OrigValue + thisRatio * attr.Value;
                break;

            case MGAttribute.Alpha:
                view.Alpha = attr.OrigValue + thisRatio * attr.Value;
                break;

            case MGAttribute.ShadowRadius:
                view.Layer.ShadowRadius = attr.OrigValue + thisRatio * attr.Value;
                break;

            case MGAttribute.ShadowOpacity:
                view.Layer.ShadowOpacity = (float)(attr.OrigValue + thisRatio * attr.Value);
                break;

            case MGAttribute.FontSize:
                if (view is UILabel)
                {
                    ((UILabel)view).Font = ((UILabel)view).Font.WithSize(attr.OrigValue + thisRatio * attr.Value);
                }
                else if (view is UIButton)
                {
                    ((UIButton)view).Font = ((UIButton)view).Font.WithSize(attr.OrigValue + thisRatio * attr.Value);
                }
                else if (view is UITextField)
                {
                    ((UITextField)view).Font = ((UITextField)view).Font.WithSize(attr.OrigValue + thisRatio * attr.Value);
                }
                else if (view is UITextView)
                {
                    ((UITextView)view).Font = ((UITextView)view).Font.WithSize(attr.OrigValue + thisRatio * attr.Value);
                }
                break;
            }
        }
Exemple #3
0
        private void UpdateConstraint(NSLayoutConstraint constraint, nfloat constraintValue, MGTransform transform, nfloat thisRatio)
        {
            if (constraint != null)
            {
                switch (constraint.FirstAttribute)
                {
                case NSLayoutAttribute.Top:
                case NSLayoutAttribute.TopMargin:
                case NSLayoutAttribute.Leading:
                case NSLayoutAttribute.LeadingMargin:
                case NSLayoutAttribute.Width:
                case NSLayoutAttribute.Height:
                    constraint.Constant = constraintValue + thisRatio * transform.Value;
                    break;

                case NSLayoutAttribute.Bottom:
                case NSLayoutAttribute.BottomMargin:
                case NSLayoutAttribute.Trailing:
                case NSLayoutAttribute.TrailingMargin:
                    constraint.Constant = constraintValue - thisRatio * transform.Value;
                    break;

                default:
                    break;
                }
            }
        }