在C#与部分静态的UITableViewController你可以使用:
using System;
using Foundation;
using UIKit;
using CoreGraphics;
using CoreAnimation;
namespace MyNamespace
{
public class CustomTableViewController : UITableViewController
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
SetGradientBackgound();
}
private void SetGradientBackgound()
{
CGColor[] colors = new CGColor[] {
UIColor.Purple.CGColor,
UIColor.Red.CGColor,
};
CAGradientLayer gradientLayer = new CAGradientLayer();
gradientLayer.Frame = this.View.Bounds;
gradientLayer.Colors = colors;
gradientLayer.StartPoint = new CGPoint(0.0, 0.0);
gradientLayer.EndPoint = new CGPoint(1.0, 1.0);
UIView bgView = new UIView()
{
Frame = this.View.Frame
};
bgView.Layer.InsertSublayer(gradientLayer, 0);
UITableView view = (UITableView)this.View;
view.BackgroundColor = UIColor.Clear;
view.BackgroundView = bgView;
}
// Setting cells background transparent
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = base.GetCell(tableView, indexPath);
cell.BackgroundColor = UIColor.Clear;
return cell;
}
// Setting sections background transparent
public override void WillDisplayHeaderView(UITableView tableView, UIView headerView, nint section)
{
if (headerView.GetType() == typeof(UITableViewHeaderFooterView))
{
UITableViewHeaderFooterView hView = (UITableViewHeaderFooterView)headerView;
hView.ContentView.BackgroundColor = UIColor.Clear;
hView.BackgroundView.BackgroundColor = UIColor.Clear;
}
}
}
}
结果可能是这样的:
来源
2018-01-23 05:07:06
gts
为什么只有.png for iOS? – 2010-08-19 15:33:15
我应该澄清 - 使用PNG处理所有不是照片的东西。 PNG由iOS设备上的GPU进行硬件加速,因此您的所有UI图像均应采用PNG格式。 PNG支持alpha透明度,这对于大量的UI图形来说是必需的。对于任何照片,JPEG压缩会给你更小的文件大小,所以这可能是一个好处。 – 2010-08-20 03:51:10
虽然这个表设置为分组样式时每个组的背景,但有没有办法解决这个问题? – 2011-05-30 10:40:57