本文整理汇总了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 });
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
//.........这里部分代码省略.........
示例6: underlineButton
// UnderlineStyle Button
public static void underlineButton (UIButton button)
{
button.SetAttributedTitle (new NSAttributedString (
button.TitleLabel.Text,
underlineStyle: NSUnderlineStyle.Single), UIControlState.Normal);
}