que premium novedades medidas medicion features apple app iphone background uitableview

premium - iPhone-Configuración de fondo en UITableViewController



premium features apple email (6)

¿Hay alguna manera de establecer una vista de fondo en un UITableViewController?

Intento con el código que estoy usando en un UIViewController , pero la vista UIViewController todos los contenidos de la vista de tabla. Si agrego la vista de fondo en el cellForRowAtIndexPath-method , no se muestra en absoluto. ¿Alguien ha hecho esto antes o tiene una idea de cómo se puede hacer? Aquí está el código que estoy usando:

UIImage *image = [UIImage imageNamed: @"background.jpg"]; UIImageView *backImage = [[UIImageView alloc] initWithImage: image]; [self.view addSubview: backImage]; [self.view sendSubviewToBack: backImage];


(Esto es básicamente lo mismo que la solución anterior de Hans Espen, pero utiliza métodos de conveniencia para la brevedad)

Pon esto en tu - [UITableViewControllerSubclass viewDidLoad] método:

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundPattern.png"]];

No tiene sentido evitar un par de autorreleases en un método viewDidLoad, ya que solo se llama raramente (cuando la vista se carga realmente) y, por lo tanto, tendrá un impacto insignificante en el rendimiento.

Nota: siempre debe usar imágenes PNG en el iPhone, no en formato JPEG o cualquier otro formato.


En C # para un UITableViewController estático con secciones, puede usar:

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; } } } }

El resultado puede ser algo como esto:


En realidad, lo tengo funcionando! :)

NSString *backgroundPath = [[NSBundle mainBundle] pathForResource:@"background" ofType:@"jpg"]; UIImage *backgroundImage = [UIImage imageWithContentsOfFile:backgroundPath]; UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage:backgroundImage]; self.tableView.backgroundColor = backgroundColor; [backgroundColor release];


Para Swift usa esto,

self.tableView.backgroundView = UIImageView(image: UIImage(named: "backgroundImage.png"))


Sé que ha pasado mucho tiempo, pero solo para el registro ... Creo que encontré una mejor solución utilizando UITableView.backgroundView :

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lisbon.png"]]; self.tableView.backgroundView = imageView; [imageView release];

Intenté con un tamaño de imagen de 320x480 en iPhone, y funciona perfectamente (lo he intentado con .jpg también).


self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yourImage.png"]];