当前位置: 首页>>代码示例>>C#>>正文


C# UIButton.SizeToFit方法代码示例

本文整理汇总了C#中UIButton.SizeToFit方法的典型用法代码示例。如果您正苦于以下问题:C# UIButton.SizeToFit方法的具体用法?C# UIButton.SizeToFit怎么用?C# UIButton.SizeToFit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UIButton的用法示例。


在下文中一共展示了UIButton.SizeToFit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateCell

        protected override StandardContentCell CreateCell(UITableView tableView)
        {
            var cell = new StandardContentCell(UITableViewCellStyle.Default, Type);
            cell.SelectionStyle = UITableViewCellSelectionStyle.None;

            button = UIButton.FromType (UIButtonType.Custom);

            button.SetTitle (Text, UIControlState.Normal);
            button.Font = UIFont.BoldSystemFontOfSize (16);
            button.BackgroundColor = BackgroundColor;
            button.TitleEdgeInsets = new UIEdgeInsets(0, 6, 0, 6);
            button.Layer.CornerRadius = 7.0f;
            button.SetTitleColor(TextColor, UIControlState.Normal);
            button.SizeToFit ();
            button.TouchUpInside += delegate {
                RowSelectedImpl (tableView);
            };

            if (Disable) {
                button.UserInteractionEnabled = false;
                button.Enabled = false;
                button.TitleLabel.Enabled = false;
            }

            float left = (tableView.Frame.Width - button.Frame.Width ) / 2 - 12;
            button.Frame = new RectangleF(left, 4, button.Frame.Width + 12, 36);

            cell.ContentView.Add (button);

            return cell;
        }
开发者ID:jivkopetiov,项目名称:StackApp,代码行数:31,代码来源:ContentRows.cs

示例2: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.Frame = new RectangleF(PointF.Empty, View.Bounds.Size);
            View.BackgroundColor = UIColor.White;

            View.BackgroundColor = UIColor.White;
            comparisonButton = UIButton.FromType(UIButtonType.RoundedRect);
            comparisonButton.SetTitle("Compare Animations", UIControlState.Normal);
            comparisonButton.SizeToFit();
            comparisonButton.Center = new PointF(View.Center.X, comparisonButton.Center.Y + 6f);
            View.Add(comparisonButton);

            tableSampleButton = UIButton.FromType(UIButtonType.RoundedRect);
            tableSampleButton.SetTitle("Table Sample", UIControlState.Normal);
            tableSampleButton.SizeToFit();
            tableSampleButton.Center = new PointF(View.Center.X, comparisonButton.Frame.Bottom + tableSampleButton.Center.Y + 6f);
            View.Add(tableSampleButton);

            comparisonButton.TouchUpInside += (sender, e) => {
                NavigationController.PushViewController(new ComparisonViewController(), animated: true);
            };

            tableSampleButton.TouchUpInside += (sender, e) => {
                NavigationController.PushViewController(new TableSampleTableViewController(), animated: true);
            };
        }
开发者ID:patridge,项目名称:SpinnningUIImageView,代码行数:28,代码来源:MenuViewController.cs

示例3: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            CGRect screenSize = UIScreen.MainScreen.Bounds;

            _cropperView = new HIPImageCropperView(
                frame: this.View.Bounds,
                cropSize: new CGSize(300, 300),
                position: HIPImageCropperView.CropperViewPosition.Center);

            this.View.AddSubview(_cropperView);

            _cropperView.SetOriginalImage(new UIImage("Images/portrait.jpg"));

            UIButton captureButton = new UIButton(UIButtonType.RoundedRect);
            captureButton.SetTitle("Capture", UIControlState.Normal);
            captureButton.SizeToFit();
            captureButton.Frame = new CGRect(this.View.Frame.Width - captureButton.Frame.Width - 10,
                this.View.Frame.Height - captureButton.Frame.Height - 10,
                captureButton.Frame.Width, captureButton.Frame.Height);

            captureButton.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleLeftMargin;
            captureButton.TouchUpInside += DidTapCaptureButton;
            this.View.AddSubview(captureButton);

            nfloat buttonSize = screenSize.Width / 3;

            for (int i = 0; i < 3; i++)
            {
                UIButton photoButton = new UIButton(UIButtonType.Custom);
                photoButton.TouchUpInside += DidTapPhotoButton;

                photoButton.Frame = new CGRect(i * buttonSize, 0, buttonSize, 50);

                string buttonTitle = string.Empty;

                switch (i)
                {
                    case 0:
                        buttonTitle = "Portrait";
                        break;
                    case 1:
                        buttonTitle = "Landscape";
                        break;
                    case 2:
                        buttonTitle = "Wide";
                        break;
                    default:
                        break;
                }

                photoButton.SetTitle(buttonTitle, UIControlState.Normal);

                this.View.AddSubview(photoButton);

                _photoButtons.Add(photoButton);
            }
        }
开发者ID:ProstoKorol,项目名称:HIPImageCropperXamarin,代码行数:59,代码来源:RootCropperViewController.cs

示例4: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            View.BackgroundColor = UIColor.White;

            _button = new UIButton (new RectangleF(10f, 30f, 0f, 0f));
            _button.TouchUpInside += HandleTouchUpInside;
            _button.SetTitle ("click me", UIControlState.Normal);
            _button.SetTitleColor (UIColor.Blue, UIControlState.Normal);
            _button.SizeToFit ();

            View.AddSubview (_button);
        }
开发者ID:TouchInstinct,项目名称:Training,代码行数:13,代码来源:MainController.cs

示例5: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor = UIColor.White;
            View.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;

            // iOS is forgiving on audio files. It will handle all three of these just fine.
            string mediaType = "caf"; //"mp3"; //"wav";
            var fileUrl = new NSUrl(NSBundle.MainBundle.PathForResource("Sounds/wubwub", mediaType), false);
            player = AVAudioPlayer.FromUrl(fileUrl);
            player.PrepareToPlay();

            button1 = new UIButton(UIButtonType.RoundedRect);
            button1.SetTitle("Make Some Noise", UIControlState.Normal);
            button1.SizeToFit();
            button1.Center = new CGPoint(View.Bounds.Width / 2f, View.Bounds.Height / 2f);
            button1.TouchUpInside += (sender, e) => {
                player.Play();
            };
            // You can tie in to the event when the sound finishes as well. Here, we just spin the button afterward.
            player.FinishedPlaying += (sender, e) => {
                // (Courtesy of http://www.patridgedev.com/2012/10/05/creating-an-animated-spinner-in-a-monotouch-uiimageview/)
                CABasicAnimation rotationAnimation = CABasicAnimation.FromKeyPath("transform.rotation");
                rotationAnimation.To = NSNumber.FromDouble(Math.PI * 2);
                rotationAnimation.RemovedOnCompletion = true;
                // Give the added animation a key for referencing it later (to remove, in this case).
                button1.Layer.AddAnimation(rotationAnimation, "rotationAnimation");
            };
            Add(button1);

            rand = new Random();
            var variousPlayers = (new[] {
                "Sounds/ding-dong",
                "Sounds/pew-beep",
                "Sounds/wee-ooo",
                "Sounds/wubwub",
            }).Select(path => {
                var url = new NSUrl(NSBundle.MainBundle.PathForResource(path, "wav"), false);
                var audioPlayer = AVAudioPlayer.FromUrl(url);
                audioPlayer.PrepareToPlay();
                return audioPlayer;
            }).ToList();
            button2 = new UIButton(UIButtonType.RoundedRect);
            button2.SetTitle("Random", UIControlState.Normal);
            button2.SizeToFit();
            button2.Center = CGPoint.Add(new CGPoint(View.Bounds.Width / 2f, View.Bounds.Height / 2f), new CGSize(0f, button1.Frame.Height + 8f));
            button2.TouchUpInside += (sender, e) => {
                variousPlayers[rand.Next(variousPlayers.Count - 1)].Play();
            };
            Add(button2);
        }
开发者ID:patridge,项目名称:UIKitAbuse,代码行数:51,代码来源:PlayingSoundsViewController.cs

示例6: MainViewController

 public MainViewController()
 {
     var button = new UIButton (UIButtonType.RoundedRect);
     button.SetTitle ("Test Button", UIControlState.Normal);
     button.SizeToFit ();
     button.TouchUpInside += (object sender, EventArgs e) => {
         var t = int.Parse(Title) + 1;
         this.NavigationController.PushViewController(new MainViewController(){
             Title = t.ToString(),
         },true);
     };
     this.Title = "0";
     this.View.AddSubview (button);
 }
开发者ID:Clancey,项目名称:countly-sdk-windows-phone,代码行数:14,代码来源:MainViewController.cs

示例7: MoreLinkButton

            public static UIButton MoreLinkButton()
            {
                var btn = new UIButton();

                btn.SetTitle(Strings.More, UIControlState.Normal);
                btn.SetTitleColor(UIColor.Blue, UIControlState.Normal);

                btn.Font = Fonts.Regular14;
                //				btn.BackgroundColor = UIColor.DarkGray;

                btn.SizeToFit();

                return btn;
            }
开发者ID:johnnypilz,项目名称:RottenTomatoes-1,代码行数:14,代码来源:UIFactory.cs

示例8: ViewDidLoad

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			View.BackgroundColor = UIColor.White;

			var loginButton = new UIButton (UIButtonType.RoundedRect);
			loginButton.SetTitle ("Log In", UIControlState.Normal);
			loginButton.SizeToFit ();
			loginButton.Center = new CGPoint (View.Bounds.GetMidX (), View.Bounds.GetMidY ());
			loginButton.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
			loginButton.TouchUpInside += LoginClick;

			View.AddSubview (loginButton);
		}
开发者ID:marcovidaurre,项目名称:TOURED,代码行数:15,代码来源:MainViewController.cs

示例9: SetupNextKeyboardButton

		void SetupNextKeyboardButton()
		{
			nextKeyboardButton = new UIButton (UIButtonType.System);

			nextKeyboardButton.SetTitle ("Next Keyboard", UIControlState.Normal);
			nextKeyboardButton.SizeToFit ();
			nextKeyboardButton.TranslatesAutoresizingMaskIntoConstraints = false;

			nextKeyboardButton.TouchUpInside += OnNextKeyboard;

			View.AddSubview (nextKeyboardButton);

			var left = NSLayoutConstraint.Create (nextKeyboardButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1, 10);
			var bottom = NSLayoutConstraint.Create (nextKeyboardButton, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0);
			View.AddConstraints (new [] { left, bottom });
		}
开发者ID:MbProg,项目名称:CustomKeyboardScanner,代码行数:16,代码来源:KeyboardViewController.cs

示例10: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            // Set up global draw button
            DrawButton = UIButton.FromType (UIButtonType.System);
            DrawButton.SetTitle ("Draw", UIControlState.Normal);
            DrawButton.TintColor = UIColor.Black;
            DrawButton.ContentEdgeInsets = new UIEdgeInsets (10, 10, 10, 10);
            DrawButton.Layer.CornerRadius = 5;
            DrawButton.SizeToFit ();
            DrawButton.TouchUpInside += HandleTouchUpInside;

            ContentView.AddSubview (DrawButton);
            UpdateDrawButtonAppearance ();
        }
开发者ID:pauldotknopf,项目名称:Xamarin-v3,代码行数:16,代码来源:PSCSimpleDrawingPDFViewController.cs

示例11: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            View.BackgroundColor = UIColor.White;

            _fbShare = new UIButton(UIButtonType.RoundedRect);
            _fbShare.TouchUpInside += OnLoginClicked;
            _fbShare.SetTitle("Share in Facebook", UIControlState.Normal);
            _fbShare.SetTitleColor (UIColor.White, UIControlState.Normal);
            _fbShare.BackgroundColor = UIColor.Blue;

            _fbShare.SizeToFit ();

            View.AddSubview (_fbShare);
            _fbShare.Begin().MoveY(50).LMargin(20).Commit();
        }
开发者ID:TouchInstinct,项目名称:Training,代码行数:17,代码来源:MainController.cs

示例12: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor = UIColor.White;
            View.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;

            char jet = '\uf0fb';
            var label = new UILabel() {
                Font = IconFont,
                Text = jet.ToString(),
                TextColor= UIColor.Green,
                BackgroundColor = UIColor.Gray,
            };
            label.SizeToFit();
            label.Center = new PointF(View.Bounds.Width / 2f, View.Bounds.Width / 2f);
            Add(label);

            var slider = new UISlider(new RectangleF(new PointF(0f, View.Bounds.Height - 50f), new SizeF(View.Bounds.Width, 50f)));
            float maxFontSize = label.Text.GetMaxFontSize(label.Font, new SizeF(View.Bounds.Width, slider.Frame.Top));
            slider.MinValue = 0.1f; // If you go to 0, you end up losing your font for some reason.
            slider.MaxValue = maxFontSize;
            slider.Value = IconFont.PointSize;
            slider.ValueChanged += (sender, e) => {
                label.Font = label.Font.WithSize(slider.Value);
                label.SizeToFit();
                label.Center = new PointF(View.Bounds.Width / 2f, View.Bounds.Width / 2f);
            };
            Add(slider);

            char refresh = '\uf021';
            var button = new UIButton(UIButtonType.RoundedRect) {
                Font = IconFont,
            };
            button.SetTitle(refresh.ToString(), UIControlState.Normal);
            button.SizeToFit();
            button.Center = new PointF(View.Bounds.Width / 2f, slider.Frame.Top - (button.Frame.Height / 2f));
            button.TouchUpInside += (sender, e) => {
                // (Courtesy of http://www.patridgedev.com/2012/10/05/creating-an-animated-spinner-in-a-monotouch-uiimageview/)
                CABasicAnimation rotationAnimation = CABasicAnimation.FromKeyPath("transform.rotation");
                rotationAnimation.To = NSNumber.FromDouble(Math.PI * 2);
                rotationAnimation.RemovedOnCompletion = true;
                // Give the added animation a key for referencing it later (to remove, in this case).
                label.Layer.AddAnimation(rotationAnimation, "rotationAnimation");
            };
            Add(button);
        }
开发者ID:patridge,项目名称:UIKitAbuse,代码行数:46,代码来源:CustomFontIconsViewController.cs

示例13: SetupMainButton

		void SetupMainButton ()
		{
			mainButton = new UIButton (UIButtonType.System);
			var fontSize = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 80 : 60;
			mainButton.TitleLabel.Font = UIFont.SystemFontOfSize (fontSize);

			mainButton.SetTitle (SingleWord, UIControlState.Normal);
			mainButton.SizeToFit ();
			mainButton.TranslatesAutoresizingMaskIntoConstraints = false;

			mainButton.TouchUpInside += PrintWord;

			View.AddSubview (mainButton);

			var x = NSLayoutConstraint.Create (mainButton, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, View, NSLayoutAttribute.CenterX, 1, 0);
			var y = NSLayoutConstraint.Create (mainButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, View, NSLayoutAttribute.CenterY, 1, 0);
			View.AddConstraints (new [] { x, y });
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:18,代码来源:KeyboardViewController.cs

示例14: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            this.View.SetDefaultGameBackgroundImage ();

            this.AddChildViewController (this.ChildController);
            this.View.AddSubview (this.ChildController.View);
            this.ChildController.DidMoveToParentViewController (this);

            var backBtn = new UIButton (UIButtonType.Custom);
            backBtn.SetImage (UIImage.FromBundle ("images/cursor_left.png"), UIControlState.Normal);
            backBtn.SizeToFit ();
            backBtn.TouchUpInside += (object sender, EventArgs e) => {
                AppDelegate.NavigateToScreen(this.ReturnToScreen);
            };
            backBtn.Center = new PointF (backBtn.Bounds.Width / 2f + 10, backBtn.Bounds.Height / 2f + 5);
            this.View.Add (backBtn);
        }
开发者ID:Krumelur,项目名称:Pyramid,代码行数:18,代码来源:GameContainerController.cs

示例15: SetupMainButton

		private void SetupMainButton ()
		{
			mainButton = new UIButton (UIButtonType.System);
			mainButton.TitleLabel.Font = UIFont.SystemFontOfSize (80);

			mainButton.SetTitle (SingleWord, UIControlState.Normal);
			mainButton.SizeToFit ();
			mainButton.TranslatesAutoresizingMaskIntoConstraints = false;

			mainButton.AddTarget (this, new Selector ("PrintWord"), UIControlEvent.TouchUpInside);

			View.AddSubview (mainButton);

			var mainButtonCenterXSideConstraint = NSLayoutConstraint.Create (mainButton, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, View, NSLayoutAttribute.CenterX, 1.0f, 0.0f);
			var mainButtonCenterYsConstraint = NSLayoutConstraint.Create (mainButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, View, NSLayoutAttribute.CenterY, 1.0f, 0.0f);
			View.AddConstraints (new [] {
				mainButtonCenterXSideConstraint,
				mainButtonCenterYsConstraint
			});
		}
开发者ID:b-theile,项目名称:monotouch-samples,代码行数:20,代码来源:KeyboardViewController.cs


注:本文中的UIButton.SizeToFit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。