2011-12-11 126 views
0

所有頁面現在,我可以改變的UITableView的背景色似更改UITableView的背景色

-(void)viewDidLoad { 
[super viewDidLoad]; 
[self.tableView setBackgroundView:nil]; 
    [self.tableView setBackgroundView:[[[UIView alloc] init] autorelease]]; 
    [self.tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"tblbg.png"]]]; 
} 

但我需要的所有文件添加代碼。我不想創建UITableView子類。

是否有可能使UITableView的類別改變背景顏色?

回答

0

似乎很容易嘗試?

的UITableView + CustomBackgroundColor.h:

@interface UITableView (CustomBackgroundColor) 

@end 

的UITableView + CustomBackgroundColor.m:

@implementation UITableView (CustomBackgroundColor) 

- (void) viewDidLoad { 
    [super viewDidLoad]; 
    [self.tableView setBackgroundView:nil]; 
    [self.tableView setBackgroundView:[[[UIView alloc] init] autorelease]]; 
    [self.tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"tblbg.png"]]]; 
} 

@end