Ejemplo n.º 1
0
        private void ConfigureMoreLessDescriptionButton( )
        {
            _isDescriptionCollapsed = true;

            const int collapsedDescriptionLineCount = 3;

            CGSize totalTextSize = new NSString(DuplicateConstraintedDescriptionLabel.Text)
                                   .GetSizeUsingAttributes(new UIStringAttributes {
                Font = DuplicateConstraintedDescriptionLabel.Font
            });

            nfloat multipleLinesOfTextTotalWidth = DuplicateConstraintedDescriptionLabel.Bounds.Size.Width * collapsedDescriptionLineCount;

            if (multipleLinesOfTextTotalWidth < totalTextSize.Width)
            {
                View.LayoutIfNeeded( );

                DuplicateConstraintedDescriptionLabel.Lines = collapsedDescriptionLineCount;

                UITapGestureRecognizer gestureRecognizer = new UITapGestureRecognizer(() =>
                {
                    // On Tap, toggle the collapsed flag.
                    _isDescriptionCollapsed = !_isDescriptionCollapsed;

                    // Update the number of lines allowed for the description & the hide/show button.
                    UIView.Animate(0.3, () =>
                    {
                        MoreLessDescriptionButton.Text = _isDescriptionCollapsed ? "Hide full description" : "Show full description";
                        DuplicateConstraintedDescriptionLabel.Lines = _isDescriptionCollapsed ? 0 : collapsedDescriptionLineCount;
                        View.LayoutIfNeeded( );
                    });
                });

                MoreLessDescriptionButton.UserInteractionEnabled = true;
                MoreLessDescriptionButton.TextColor = UIColor.Clear.FromHex("#0cb6ea");
                MoreLessDescriptionButton.AddGestureRecognizer(gestureRecognizer);
            }
            else
            {
                HideMoreLessDescriptionButton( );
            }
        }
        void ReleaseDesignerOutlets()
        {
            if (MoreLessDescriptionHeightConstraint != null)
            {
                MoreLessDescriptionHeightConstraint.Dispose();
                MoreLessDescriptionHeightConstraint = null;
            }

            if (DescriptionDetailsLabel != null)
            {
                DescriptionDetailsLabel.Dispose();
                DescriptionDetailsLabel = null;
            }

            if (DuplicateConstraintedDescriptionLabel != null)
            {
                DuplicateConstraintedDescriptionLabel.Dispose();
                DuplicateConstraintedDescriptionLabel = null;
            }

            if (ImageCollectionView != null)
            {
                ImageCollectionView.Dispose();
                ImageCollectionView = null;
            }

            if (ImageCollectionViewHeightConstraint != null)
            {
                ImageCollectionViewHeightConstraint.Dispose();
                ImageCollectionViewHeightConstraint = null;
            }

            if (MoreLessDescriptionButton != null)
            {
                MoreLessDescriptionButton.Dispose();
                MoreLessDescriptionButton = null;
            }
        }