本文介绍了带有文本的显示按钮Xamarin IOS 中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 Xamarin IOS 中设计一个自定义按钮来显示文本和图像.请找到下面的图片.
I want to design a custom button in Xamarin IOS to display both Text and Image.Please find the below image.
您可以在上图中找到文本和向下箭头符号.向下箭头符号应始终显示在文本之后.按钮文本是动态的.
You can find the Text and down arrow symbol in the above image.the down arrow symbol should always display after the text. The button text is dynamic.
谁能建议我解决这个问题.
Can any one suggest me to solve this.
推荐答案
您想使用 TitleEdgeInsets
&UIButton
的 ImageEdgeInsets
属性来控制文本和图像的插入位置:
You want to use the TitleEdgeInsets
& ImageEdgeInsets
properties of the UIButton
to control where the inset of the text and image begins:
button.TitleEdgeInsets = new UIEdgeInsets(0, -button.ImageView.Frame.Size.Width, 0, button.ImageView.Frame.Size.Width);
button.ImageEdgeInsets = new UIEdgeInsets(0, button.TitleLabel.Frame.Size.Width, 0, -button.TitleLabel.Frame.Size.Width);
完整示例:
button = new UIButton(UIButtonType.System);
button.Frame = new CGRect(150, 20, 200, 50);
button.Layer.CornerRadius = 5;
button.BackgroundColor = UIColor.Black;
button.SetTitleColor(UIColor.White, UIControlState.Normal);
button.SetImage(UIImage.FromFile("ratingstar.png"), UIControlState.Normal);
button.SetTitle("StackOverflow", UIControlState.Normal);
button.TitleEdgeInsets = new UIEdgeInsets(0, -button.ImageView.Frame.Size.Width, 0, button.ImageView.Frame.Size.Width);
button.ImageEdgeInsets = new UIEdgeInsets(0, button.TitleLabel.Frame.Size.Width, 0, -button.TitleLabel.Frame.Size.Width);
这篇关于带有文本的显示按钮Xamarin IOS 中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!