![](/img/trans.png)
[英]How to change the tab bar background image to transparent image in ios sdk
[英]iOS tab bar background image propgrammatically
我想以编程方式在Tabor中的项目之间创建分隔符。 然后我编写了这段代码,但是什么也没显示。
float separator_width = 3f;
UIColor separator_color = UIColor.Red;
float itemWidth = (float)Math.Floor(this.TabBar.Frame.Width / this.TabBar.Items.Length);
UIView bgView = new UIView();
bgView.Frame = new CGRect(0, 0, this.TabBar.Frame.Width, this.TabBar.Frame.Height);
for (int i = 0; i < this.TabBar.Items.Length; i++)
{
UIView separator = new UIView();
separator.Frame = new CGRect(itemWidth * (i + 1) - separator_width / 2, 0, separator_width, this.TabBar.Frame.Height);
bgView.Add(separator);
}
UIGraphics.BeginImageContext(new CGSize(bgView.Frame.Width, bgView.Frame.Height));
bgView.Layer.RenderInContext(UIGraphics.GetCurrentContext());
UIImage tabBarBackground = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
UITabBar.Appearance.BackgroundImage = tabBarBackground;
我试图编写它并以另一种视图显示它,但是什么也没有。 我能做什么 ?
谢谢
我找到了另一个解决方案。 对于那些搜索的人:
查看以下内容:
var image = new UIImage();
var path = new UIBezierPath();
var lineHeight = 42.5f;
float itemWidth = (float)Math.Floor(this.TabBar.Frame.Width / this.TabBar.Items.Length);
UIGraphics.BeginImageContextWithOptions(new CGSize(this.TabBar.Frame.Width, this.TabBar.Frame.Height), false, 0);
image.Draw(new CGPoint(0,0));
UIColor.Clear.FromHex(0xF2F2F2).SetStroke();
path.LineWidth = 1;
for (int i = 1; i < this.TabBar.Items.Length; i++)
{
path.MoveTo(new CGPoint(itemWidth * i - path.LineWidth / 2, (this.TabBar.Frame.Height - lineHeight) / 2));
path.AddLineTo(new CGPoint(itemWidth * i - path.LineWidth / 2, lineHeight + (this.TabBar.Frame.Height - lineHeight) / 2));
}
path.Stroke();
image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
UITabBar.Appearance.BackgroundImage = image;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.