Exemplo n.º 1
0
        void Apply(StyleRuleSet ruleset, StyleApplier applier, UIView parentView)
        {
            var styles = ruleset.StylesFor (parentView);
            foreach (var style in styles) {
                applier.Apply (parentView, style);
            }

            foreach (var view in parentView.Subviews) {
                Apply (ruleset, applier, view);
            }
        }
Exemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            // obviously the ruleset should be from a file somehow...
            var ruleset = new StyleRuleSet();

            var rule = new Rule();
            rule.Selectors.Add(new Selector(typeof(UILabel)));
            rule.Styles.Add(new SimpleStyle("Color", UIColor.Green));
            rule.Styles.Add(new SimpleStyle("CornerRadius", 10f));
            rule.Styles.Add(new SimpleStyle("BackgroundColor", UIColor.Blue));
            ruleset.Rules.Add(rule);

            rule = new Rule();
            rule.Selectors.Add(new Selector(typeof(UIButton)));
            rule.Styles.Add(new SimpleStyle("Color", UIColor.Cyan));
            rule.Styles.Add(new SimpleStyle("CornerRadius", 30f));
            rule.Styles.Add(new SimpleStyle("BackgroundColor", UIColor.Orange));
            rule.Styles.Add(new SimpleStyle("ShadowOffset", new SizeF(4, 10)));
            rule.Styles.Add(new SimpleStyle("ShadowRadius", 7f));
            rule.Styles.Add(new SimpleStyle("ShadowColor", UIColor.Black));
            rule.Styles.Add(new SimpleStyle("ShadowOpacity", 0.9f));
            rule.Styles.Add(new SimpleStyle("BorderColor", UIColor.Magenta));
            rule.Styles.Add(new SimpleStyle("BorderWidth", 3.0f));
            rule.Styles.Add(new SimpleStyle("Font", new FontDescription()
                                            {
                FontName = "Chalkduster",
                FontSize = 24f
            }));

            //
            ruleset.Rules.Add(rule);

            rule = new Rule();
            rule.Selectors.Add(new Selector(typeof(UILabel), "Foo"));
            rule.Styles.Add(new SimpleStyle("Color", UIColor.Magenta));
            rule.Styles.Add(new SimpleStyle("CornerRadius", 0f));
            rule.Styles.Add(new SimpleStyle("Font", new FontDescription()
                                            {
                FontName = "Baskerville-BoldItalic",
                FontSize = 24f
            }));
            ruleset.Rules.Add(rule);

            rule = new Rule();
            var parentSelector = new Selector(typeof(UIButton));
            rule.Selectors.Add(new Selector(typeof(UILabel), null, parentSelector));
            rule.Styles.Add(new SimpleStyle("BackgroundColor", UIColor.Black));
            ruleset.Rules.Add(rule);

            // would be nice to find another way to store these class hooks
            // could just about use Tag fields - but that's unpleasant :/
            StyleClassList = new StyleClassList();
            StyleClassList.AddClass(SpecialLabel, "Foo");

            StyleFinderHelper.CurrentList = StyleClassList;
            var applier = new StyleApplier();
            Apply (ruleset, applier, View);
        }