开发者

UITableView not showing background image

I have a uitableview with 2 cells (custom tableviewcells) and a button for login. I made them programmatically. Now I want to put a background image behind the 2 custom cells and the button. I went into IB and put the image view on top of the tableview and then put a picture on it which I want as the background. Then I went into viewDidLoad and put this bit of code tblSimpleTable.backgroundColor = [UIColor clearColor]; to clear the tableviews background colour.

It now looks like this:

UITableView not showing background image

But the background does not appear. Does anyone know how to fix this?

Thanks.

viewDidLoad

  - (void)viewDidLoad {
 [super viewDidLoad];

self.dataSourceArray = [NSArray arrayWithObjects:
                        [NSDictionary dictionaryWithObjectsAndKeys:
                         @"UITextField", kSectionTitleKey,
                         @"TextFieldController.m: textFieldNormal", kSourceKey,
                         self.textFieldNormal, kViewKey,
                         nil],
                        nil];

UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
loginButton.frame = CGRectMake(60,140,200,38); // position in the cell and set the size of the button
[loginButton setTitle:@"Login" forState:UIControlStateNormal];
// add targets and actions
[loginButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
// add to a view
[self.view addSubview:loginButton];

tblSimpleTable.backgroundColor = [UIColor clearColor];
//tblSimpleTable.backgroundView = nil; 

//UIImageView *imageView = [[UIImag开发者_StackOverflow中文版eView alloc] initWithImage:@"Background-Red.png"];
//imageView.frame = tblSimpleTable.frame;
//tblSimpleTable.backgroundView = imageView;

self.title = NSLocalizedString(@"TextFieldTitle", @"");

// we aren't editing any fields yet, it will be in edit when the user touches an edit field
self.editing = NO;
 }


Why don't you use backgroundView property of the UITableView object?

UIImageView * imageView = [[UIImageView alloc] initWithImage:yourBackgroundImage];
imageView.frame = tblSimpleTable.frame;
tblSimpleTable.backgroundView = imageView;

Of course, backgroundView will be resized if you don't set the frame so skipping the second line should also not be a problem.


What you have should probably work out. Still try this :
Add

tblSimpleTable.backgroundView = nil;  

in viewDidLoad

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜