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


C# UIButton.SetAttributedTitle方法代码示例

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


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

示例1: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            // Build UI
            View.BackgroundColor = UIColor.FromRGB( 0xff, 0x74, 0x02 );

            _button = new UIButton {
                BackgroundColor = UIColor.White,
                Frame = new CGRect(20, View.Frame.Height - 80, View.Frame.Width - 40, 60)
            };
            _button.Layer.CornerRadius = 6;
            _button.SetAttributedTitle (new Foundation.NSAttributedString ("Launch Alert", new UIStringAttributes {
                ForegroundColor = View.BackgroundColor,
                Font = UIFont.SystemFontOfSize(18f),
            }), UIControlState.Normal);
            _button.TouchUpInside += (object sender, EventArgs e) => {
                LaunchAlert();
            };

            _text = new UILabel {
                Text = _preAcceptText,
                Frame = new CGRect(20, 20, View.Frame.Width - 40, _button.Frame.Top - 40),
                TextColor = UIColor.White,
                Font = UIFont.SystemFontOfSize(18f),
                TextAlignment = UITextAlignment.Center,
                Lines = 0
            };

            View.AddSubviews (new UIView[]{ _button, _text });
        }
开发者ID:FrederickEskens,项目名称:Totem,代码行数:30,代码来源:ViewController.cs

示例2: LoadView

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

            this.View.Layer.BackgroundColor = ColorScheme.Clouds.CGColor;

            SearchButton = new UIButton();
            holderView = new UIView(this.View.Frame);
            SearchTableView = new UITableView(new CGRect(), UITableViewStyle.Grouped);
            scrollView = new UIScrollView(this.View.Frame);
            SearchCityLabel = new UILabel { TextAlignment = UITextAlignment.Center };
            SearchCityLabel.AttributedText = new NSAttributedString(String.Format("Search {0} for:", Location.SiteName), Constants.LabelAttributes);

            ads = new ADBannerView();

            SearchButton.Layer.BackgroundColor = ColorScheme.MidnightBlue.CGColor;
            SearchButton.Layer.CornerRadius = 10;
            SearchButton.ClipsToBounds = true;
            SearchButton.SetAttributedTitle(new NSAttributedString("Search", Constants.ButtonAttributes), UIControlState.Normal);

            SearchTableView.Layer.BackgroundColor = ColorScheme.Clouds.CGColor;

            holderView.AddSubviews(new UIView[] { SearchButton, SearchCityLabel, SearchTableView, ads });
            scrollView.AddSubview(holderView);
            this.View.AddSubview(scrollView);

            AddLayoutConstraints();

            saveButton = new UIBarButtonItem(
                UIImage.FromFile("save.png"),
                UIBarButtonItemStyle.Plain,
                SaveButtonClicked);

            NavigationItem.RightBarButtonItem = saveButton;
        }
开发者ID:erdennis13,项目名称:EthansList,代码行数:35,代码来源:SearchViewController.cs

示例3: SetText

        private static void SetText(Labs.Controls.IconButton iconButton, UIButton targetButton)
        {
            var renderedIcon = iconButton.Icon;

            // if no IconFontName is provided on the IconButton, default to FontAwesome
            var iconFontName = string.IsNullOrEmpty(iconButton.IconFontName)
                ? "fontawesome"
                : iconButton.IconFontName;

            var iconSize = iconButton.IconSize == default(float)
                ? 17f
                : iconButton.IconSize;

            var faFont = UIFont.FromName(iconFontName, iconSize);

            // set the icon to either be on the left or right of the button's text
            string combinedText = iconButton.Orientation == ImageOrientation.ImageToLeft 
                ? string.Format("{0}  {1}", renderedIcon, iconButton.Text) 
                : string.Format("{0}  {1}", iconButton.Text, renderedIcon);


            // string attributes for the icon
            var iconAttributes = new UIStringAttributes
            {
                ForegroundColor = iconButton.IconColor.ToUIColor(),
                BackgroundColor = targetButton.BackgroundColor,
                Font = faFont,
                TextAttachment = new NSTextAttachment()
            };

            // string attributes for the button's text. 
            // TODO: Calculate an appropriate BaselineOffset for the main button text in order to center it vertically relative to the icon
            var btnAttributes = new UIStringAttributes
            {
                BackgroundColor = iconButton.BackgroundColor.ToUIColor(),
                ForegroundColor = iconButton.TextColor.ToUIColor(),
                Font = GetButtonFont(iconButton,targetButton)
            };

            // Give the overall string the attributes of the button's text
            var prettyString = new NSMutableAttributedString(combinedText,btnAttributes);

            // Set the font for only the icon (1 char)
            prettyString.SetAttributes(iconAttributes.Dictionary,
                iconButton.Orientation == ImageOrientation.ImageToLeft
                    ? new NSRange(0, 1)
                    : new NSRange(prettyString.Length - 1, 1));


            // set the final formatted string as the button's text
            targetButton.SetAttributedTitle(prettyString, UIControlState.Normal);

            // center the button's contents
            targetButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
            targetButton.TitleLabel.TextAlignment = UITextAlignment.Center;
        }
开发者ID:Gunner92,项目名称:Xamarin-Forms-Labs,代码行数:56,代码来源:IconButtonRenderer.cs

示例4: FeedTags

        private void FeedTags (List<string> tagNames, UIButton btn)
        {
            // Construct tags attributed strings:
            NSMutableAttributedString text = null;
            foreach (var tag in tagNames) {

                var chip = NSAttributedString.CreateFrom (new NSTextAttachment {
                    Image = ServiceContainer.Resolve<TagChipCache> ().Get (tag, btn),
                });

                if (text == null) {
                    text = new NSMutableAttributedString (chip);
                } else {
                    text.Append (new NSAttributedString (" ", Style.EditTimeEntry.WithTags));
                    text.Append (chip);
                }
            }

            if (text == null) {
                btn.SetAttributedTitle (new NSAttributedString ("EditEntryTagsHint".Tr (), Style.EditTimeEntry.NoTags), UIControlState.Normal);
            } else {
                btn.SetAttributedTitle (text, UIControlState.Normal);
            }
        }
开发者ID:eatskolnikov,项目名称:mobile,代码行数:24,代码来源:EditTimeEntryViewController.cs

示例5: SetText

        private static void SetText(IconButton iconButton, UIButton targetButton)
        {
            var renderedIcon = iconButton.Icon;

            // if no IconFontName is provided on the IconButton, default to FontAwesome
            var iconFontName = string.IsNullOrEmpty(iconButton.IconFontName)
                ? "fontawesome"
                : iconButton.IconFontName;

            var iconSize = iconButton.IconSize == default(float)
                ? 17f
                : iconButton.IconSize;



            var faFont = UIFont.FromName(iconFontName, iconSize);
            string combinedText = null;
            string separator = " ";
            if (iconButton.ShowIconSeparator)
                separator = " | ";
            switch (iconButton.Orientation)
            {
                case ImageOrientation.ImageToLeft:
                    if (string.IsNullOrEmpty(iconButton.Text))
                        combinedText = renderedIcon;
                    else
                    {

                        combinedText = renderedIcon + separator + iconButton.Text;
                    }
                    break;
                case ImageOrientation.ImageToRight:
                    if (string.IsNullOrEmpty(iconButton.Text))
                        combinedText = renderedIcon;
                    else
                        combinedText = iconButton.Text + separator + renderedIcon;
                    break;
                case ImageOrientation.ImageOnTop:
                    if (string.IsNullOrEmpty(iconButton.Text))
                        combinedText = renderedIcon;
                    else
                        combinedText = renderedIcon + separator + iconButton.Text;
                    break;
                case ImageOrientation.ImageOnBottom:
                    if (string.IsNullOrEmpty(iconButton.Text))
                        combinedText = renderedIcon;
                    else
                        combinedText = renderedIcon + separator + iconButton.Text;
                    break;
            }
          


            // string attributes for the icon
            var iconAttributes = new UIStringAttributes
            {
                ForegroundColor = iconButton.IconColor.ToUIColor(),
                BackgroundColor = targetButton.BackgroundColor,
                Font = faFont,
                TextAttachment = new NSTextAttachment()
            };

           
            // string attributes for the button's text. 
            // TODO: Calculate an appropriate BaselineOffset for the main button text in order to center it vertically relative to the icon
            var btnAttributes = new UIStringAttributes
            {
                BackgroundColor = iconButton.BackgroundColor.ToUIColor(),
                ForegroundColor = iconButton.TextColor.ToUIColor(),
                Font = GetButtonFont(iconButton, targetButton),

            };
            if (!string.IsNullOrEmpty(iconButton.Text))
                btnAttributes.BaselineOffset = 3;

            // Give the overall string the attributes of the button's text
            var prettyString = new NSMutableAttributedString(combinedText, btnAttributes);

            // Set the font for only the icon (1 char)
            prettyString.SetAttributes(iconAttributes.Dictionary,
                iconButton.Orientation == ImageOrientation.ImageToLeft
                    ? new NSRange(0, 1)
                    : new NSRange(prettyString.Length - 1, 1));


       

            // set the final formatted string as the button's text
            targetButton.SetAttributedTitle(prettyString, UIControlState.Normal);

            if (iconButton.TextAlignement == TextAlignment.Center)
            {
                // center the button's contents
                targetButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
                targetButton.TitleLabel.TextAlignment = UITextAlignment.Center;
            }
            else if (iconButton.TextAlignement == TextAlignment.End)
            {
                targetButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Right;
                targetButton.TitleLabel.TextAlignment = UITextAlignment.Right;
//.........这里部分代码省略.........
开发者ID:renatojunior2009,项目名称:Xamarin-Forms-Labs,代码行数:101,代码来源:IconButtonRenderer.cs

示例6: underlineButton

		// UnderlineStyle Button
		public static void underlineButton (UIButton button)
		{
			button.SetAttributedTitle (new NSAttributedString (
				button.TitleLabel.Text, 
				underlineStyle: NSUnderlineStyle.Single), UIControlState.Normal);
		}
开发者ID:borain89vn,项目名称:demo2,代码行数:7,代码来源:MUtils.cs


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