【发布时间】:2011-06-22 08:05:18
【问题描述】:
我有一个带有 2 个单元格(自定义 tableviewcells)和一个用于登录的按钮的 uitableview。我以编程方式制作它们。现在我想在 2 个自定义单元格和按钮后面放置一个背景图像。我进入 IB 并将图像视图放在 tableview 的顶部,然后在上面放一张我想要作为背景的图片。然后我进入viewDidLoad并输入这段代码tblSimpleTable.backgroundColor = [UIColor clearColor];来清除tableviews的背景颜色。
现在看起来像这样:
但是背景没有出现。有谁知道如何解决这一问题?
谢谢。
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 = [[UIImageView 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;
}
【问题讨论】:
-
你把图片放在上面了吗?你能详细说明你是如何做到这一点的或显示一些代码吗?
-
首先放置 ImageView 并在该 ImageView 上,将您的标签和所有内容放入 Nib 文件中
-
@dragon112 + Marvin:我在 viewDidLoad 中的代码如上所示。
标签: iphone uitableview uiimageview uibutton