예제 #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

              Title = "Font test";

              _view = new UITableView(new CGRect(), UITableViewStyle.Grouped);
              View.Add(_view);

              _view.FitToParent();

              _view.RowHeight = UITableView.AutomaticDimension;
              _view.EstimatedRowHeight = 100;

              var cellFactory = new FontCellFactory();

              var source = new TableSource();
              _view.Source = source;

              Section section;
              UIFont font;
              FontModel fontModel;

              // --------------------------------------------------

              section = new Section();
              source.Sections.Add(section);

              section.Header = "Defaults";

              font = UIFont.PreferredBody;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredBody",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              font = UIFont.PreferredCaption1;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredCaption1",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              font = UIFont.PreferredCaption2;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredCaption2",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              font = UIFont.PreferredFootnote;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredFootnote",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              font = UIFont.PreferredHeadline;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredHeadline",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              font = UIFont.PreferredSubheadline;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredSubheadline",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              // --------------------------------------------------

              section = new Section();
              source.Sections.Add(section);

              font = UIFont.SystemFontOfSize(UIFont.LabelFontSize);
              section.Header = font.Name;

              fontModel = new FontModel {
            Text = $"{font.PointSize} default label font w/ size",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              for ( int size = 3; size <= 60; size += 3 )
              {
            font = UIFont.SystemFontOfSize(size);
            fontModel = new FontModel {
              Text = $"{font.PointSize} the quick brown fox jumps over the lazy dog",
              Font = font
            };
            section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));
              }
        }
예제 #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

              View.BackgroundColor = UIColor.Green;

              Title = "YxTableTest";

              _view = new UITableView(new CGRect(), UITableViewStyle.Grouped);
              View.Add(_view);

              //_view.SeparatorInset = UIEdgeInsets.Zero;
              //_view.LayoutMargins = UIEdgeInsets.Zero;
              //_view.SeparatorStyle = UITableViewCellSeparatorStyle.None;

              _view.FitToParent();

              var source = new TableSource();

              Section section;

              // -----------------------

              section = new Section();
              section.Header = "Default cell";
              section.Footer = "---";

              var defaultCellFactory = new DefaultCellFactory();

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              defaultCellFactory,
              new ItemWithTitle { Title = "foo" }
            ));

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              defaultCellFactory,
              new ItemWithTitle { Title = "bar" }
            ));

              source.Sections.Add(section);

              // -----------------------

              section = new Section();
              section.Header = "Subtitle";

              section.Cells.Add(
            new CellModel<ItemWithTitleAndSubtitle>(
              Singleton<SubtitleCellFactory>._,
              new ItemWithTitleAndSubtitle { Title = "abc", SubTitle = "123" }
            ));

              source.Sections.Add(section);

              // -----------------------

              section = new Section();
              section.Header = "Switch cell";

              var changingModel = new ItemWithTitle { Title = "This will change when switch is toggled" };
              var changingCell = new CellModel<ItemWithTitle>(defaultCellFactory, changingModel);
              section.Cells.Add( changingCell );

              var switchCellFactory1 = new SwitchCellFactory { InitialState = true };
              var switchCellFactory2 = new SwitchCellFactory {
            InitialState = false,
            CellSelected = (cell) => MsgBox.Show(cell.Model.Title, "Cell selected", new [] {"OK"}),
            Toggled = (cell) => {
              changingCell.Model.Title = "You changed me!";
              _view.ReloadCellModel(changingCell);
            }
              };

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              switchCellFactory1,
              new ItemWithTitle { Title = "foo" }
            ));

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              switchCellFactory2,
              new ItemWithTitle { Title = "Toggling this will change above text. Hopafully." }
            ));

              source.Sections.Add(section);

              // -----------------------

              section = new Section();
              section.Header = "Custom 1";

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              Singleton<CustomCellFactory1>._,
              new ItemWithTitle { Title = "abc" }
            ));

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              Singleton<CustomCellFactory1>._,
              new ItemWithTitle { Title = "def" }
            ));

              source.Sections.Add(section);

              // -----------------------

              section = new Section();
              section.Header = "Custom 2";
              //section2.Footer = "Footer 2";

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              Singleton<CustomCellFactory2>._,
              new ItemWithTitle { Title = "abc" }
            ));

              section.Cells.Add(
            new CellModel<ItemWithTitle>(
              Singleton<CustomCellFactory2>._,
              new ItemWithTitle { Title = "def" }
            ));

              source.Sections.Add(section);

              // -----------------------

              _view.Source = source;
        }