/// A circle-shape background view of target view public static void AddTargetHolder(this MaterialShowcase materialShowcase, CGPoint atCenter) { materialShowcase.hiddenTargetHolderView = new UIView(); materialShowcase.hiddenTargetHolderView.Hidden = true; materialShowcase.targetHolderView = new UIView(new CGRect(0, 0, materialShowcase.targetHolderRadius * 2, materialShowcase.targetHolderRadius * 2)); materialShowcase.targetHolderView.Center = atCenter; materialShowcase.targetHolderView.BackgroundColor = materialShowcase.targetHolderColor; materialShowcase.targetHolderView.AsCircle(); materialShowcase.hiddenTargetHolderView.Frame = materialShowcase.targetHolderView.Frame; materialShowcase.targetHolderView.Transform = CGAffineTransform.MakeScale(1 / MaterialShowcase.AniTargetHolderScale, 1 / MaterialShowcase.AniTargetHolderScale); // Initial set to support animation materialShowcase.AddSubview(materialShowcase.hiddenTargetHolderView); materialShowcase.AddSubview(materialShowcase.targetHolderView); }
/// Configures and adds primary label view public static void AddInstructionView(this MaterialShowcase materialShowcase, CGPoint atCenter) { materialShowcase.instructionView = new MaterialShowcaseInstructionView(); materialShowcase.instructionView.primaryTextFont = materialShowcase.primaryTextFont; materialShowcase.instructionView.primaryTextSize = materialShowcase.primaryTextSize; materialShowcase.instructionView.primaryTextColor = materialShowcase.primaryTextColor; materialShowcase.instructionView.primaryText = materialShowcase.primaryText; materialShowcase.instructionView.secondaryTextFont = materialShowcase.secondaryTextFont; materialShowcase.instructionView.secondaryTextSize = materialShowcase.secondaryTextSize; materialShowcase.instructionView.secondaryTextColor = materialShowcase.secondaryTextColor; materialShowcase.instructionView.secondaryText = materialShowcase.secondaryText; // Calculate x position var xPosition = MaterialShowcase.LabelMargin; // Calculate y position float yPosition; if (materialShowcase.GetTargetPosition(materialShowcase.targetView, materialShowcase.containerView) == TargetPosition.Above) { yPosition = (float)atCenter.Y + MaterialShowcase.TextCenterOffset; } else { yPosition = (float)atCenter.Y - MaterialShowcase.TextCenterOffset - MaterialShowcase.LabelDefaultHeight * 2; } materialShowcase.instructionView.Frame = new CGRect( xPosition, yPosition, materialShowcase.containerView.Frame.Width - (xPosition + xPosition), 0); materialShowcase.AddSubview(materialShowcase.instructionView); }
/// A background view which add ripple animation when showing target view public static void AddTargetRipple(this MaterialShowcase materialShowcase, CGPoint atCenter) { materialShowcase.targetRippleView = new UIView(new CGRect(0, 0, materialShowcase.targetHolderRadius * 2, materialShowcase.targetHolderRadius * 2)); materialShowcase.targetRippleView.Center = atCenter; materialShowcase.targetRippleView.BackgroundColor = materialShowcase.aniRippleColor; materialShowcase.targetRippleView.Alpha = .0f; //set it invisible materialShowcase.targetRippleView.AsCircle(); materialShowcase.AddSubview(materialShowcase.targetRippleView); }
/// Create a copy view of target view /// It helps us not to affect the original target view public static void AddTarget(this MaterialShowcase materialShowcase, CGPoint atCenter) { materialShowcase.targetCopyView = materialShowcase.targetView.SnapshotView(true); if (materialShowcase.shouldSetTintColor) { materialShowcase.targetCopyView.SetTintColor(materialShowcase.targetTintColor, true); if (materialShowcase.targetCopyView is UIButton) { UIButton button = materialShowcase.targetView as UIButton; UIButton buttonCopy = materialShowcase.targetCopyView as UIButton; buttonCopy.SetImage(button.ImageForState(UIControlState.Normal)?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), UIControlState.Normal); buttonCopy.SetTitleColor(materialShowcase.targetTintColor, UIControlState.Normal); buttonCopy.Enabled = true; } else if (materialShowcase.targetCopyView is UIImageView) { UIImageView imageView = materialShowcase.targetView as UIImageView; UIImageView imageViewCopy = materialShowcase.targetCopyView as UIImageView; imageViewCopy.Image = imageView.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); } else if (materialShowcase.targetCopyView.Subviews.FirstOrDefault() is UIImageView && materialShowcase.targetCopyView.Subviews.LastOrDefault() is UILabel) { UIImageView imageViewCopy = materialShowcase.targetCopyView.Subviews.First() as UIImageView; UILabel labelCopy = materialShowcase.targetCopyView.Subviews.Last() as UILabel; UIImageView imageView = (UIImageView)materialShowcase.targetView.Subviews.First(); imageViewCopy.Image = imageView.Image?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); labelCopy.TextColor = materialShowcase.targetTintColor; } else if (materialShowcase.targetCopyView is UILabel) { (materialShowcase.targetCopyView as UILabel).TextColor = materialShowcase.targetTintColor; } } var width = materialShowcase.targetCopyView.Frame.Width; var height = materialShowcase.targetCopyView.Frame.Height; materialShowcase.targetCopyView.Frame = new CGRect(0, 0, width, height); materialShowcase.targetCopyView.Center = atCenter; materialShowcase.targetCopyView.TranslatesAutoresizingMaskIntoConstraints = true; materialShowcase.AddSubview(materialShowcase.targetCopyView); }
/// Configures and adds primary label view public static void AddInstructionView(this MaterialShowcase materialShowcase, CGPoint atCenter) { materialShowcase.instructionView = new MaterialShowcaseInstructionView(); materialShowcase.instructionView.primaryTextFont = materialShowcase.primaryTextFont; materialShowcase.instructionView.primaryTextSize = materialShowcase.primaryTextSize; materialShowcase.instructionView.primaryTextColor = materialShowcase.primaryTextColor; materialShowcase.instructionView.primaryText = materialShowcase.primaryText; materialShowcase.instructionView.secondaryTextFont = materialShowcase.secondaryTextFont; materialShowcase.instructionView.secondaryTextSize = materialShowcase.secondaryTextSize; materialShowcase.instructionView.secondaryTextColor = materialShowcase.secondaryTextColor; materialShowcase.instructionView.secondaryText = materialShowcase.secondaryText; materialShowcase.instructionView.dismissText = materialShowcase.dismissText; materialShowcase.instructionView.dismissTextFont = materialShowcase.dismissTextFont; materialShowcase.instructionView.dismissTextColor = materialShowcase.dismissTextColor; materialShowcase.instructionView.dismissBackgroundColor = materialShowcase.dismissBackgroundColor; // Calculate x position var xPosition = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && UIDevice.CurrentDevice.Orientation.IsLandscape() ? MaterialShowcase.LabelMargin + SideMenuWidth : MaterialShowcase.LabelMargin; // Calculate y position float yPosition; if (materialShowcase.GetTargetPosition(materialShowcase.targetView, materialShowcase.containerView) == TargetPosition.Above) { yPosition = (float)atCenter.Y + MaterialShowcase.TextCenterOffset; } else { yPosition = (float)atCenter.Y - MaterialShowcase.TextCenterOffset - MaterialShowcase.LabelDefaultHeight * 2; } materialShowcase.instructionView.Frame = new CGRect( xPosition, yPosition, materialShowcase.containerView.Frame.Width - (xPosition + xPosition), 0); materialShowcase.AddSubview(materialShowcase.instructionView); }