我正在使用Xamarin开发iPhone应用程序。
我有一个1x2像素的图像,我想垂直平铺以在xib
中形成虚线,但是我看不到任何简单的方法来做到这一点。 Xcode没有可用于 slice 的内容模式,尽管Xamarin中的UIImage类具有ResizingMode属性,但它是只读的!
有没有使该工作正常的方法?
最佳答案
怎么样:
UIView tiledView = new UIView();
UIImage image = UIImage.FromFile("your_image.png");
tiledView.BackgroundColor = UIColor.FromPatternImage(image);
在UITableViewCell上,BackgroundColor属性不可用,因为它被UITableView覆盖。作为解决方法,我要做的是:
private UIView background;
public override void AwakeFromnib() {
base.AwakeFromNib();
this.background = new UIView();
this.background.BackgroundColor = UIColor.Blue;
this.AddSubview(this.background);
}
public override void LayoutSubviews() {
base.LayoutSubviews();
this.background.Frame = this.Bounds;
}
只需根据需要更改BackgroundColor。
关于ios - 如何平铺图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17790734/