当表视图存在时,UIToolbar上的白线

时间:2009-12-02 04:20:15

标签: iphone objective-c uitableview uitoolbar

我在几个视图中以编程方式创建了UIToolbar。在我看来有一个表格的视图中,工具栏中间有一条白线,它似乎是表格单元格边框的位置。有没有办法摆脱这条线?

这是一个屏幕截图:

iphone table with white bar

这是我用来创建所示工具栏的代码:

- (void) createToolbarItems {
UIBarButtonItemStyle style = UIBarButtonItemStylePlain;

UIImage *addWishImg = [UIImage imageNamed:@"btn-addwish-off.png"];
UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[addBtn setImage:addWishImg forState:UIControlStateNormal];
addBtn.frame = CGRectMake(0, 0, addWishImg.size.width, addWishImg.size.height);
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithCustomView:addBtn];
[addButton setTarget:self];
[addButton setAction:@selector(addWish)];
addButton.style = style;

UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                          target:nil
                                                                          action:nil];
flexItem.style = style;

UIImage *emailImg = [UIImage imageNamed:@"btn-mail-off.png"];
UIButton *emailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[emailBtn setImage:emailImg forState:UIControlStateNormal];
emailBtn.frame = CGRectMake(0, 0, emailImg.size.width, emailImg.size.height);
UIBarButtonItem *emailButton = [[UIBarButtonItem alloc] initWithCustomView:emailBtn];
[emailButton setTarget:self];
[emailButton setAction:@selector(addWish)];
emailButton.style = style;

NSArray *items = [NSArray arrayWithObjects: addButton, flexItem, emailButton, nil];
[self.toolbar setItems:items animated:NO];

[addButton release];
[flexItem release];
[emailButton release];

}

- (void)viewDidLoad {
[super viewDidLoad];

…

// create the UIToolbar at the bottom of the view controller
toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlackOpaque;

// size up the toolbar and set its frame
[toolbar sizeToFit];
CGFloat toolbarHeight = [toolbar frame].size.height;
NSLog(@"%f", toolbarHeight);
CGRect mainViewBounds = self.view.bounds;
[toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
                             CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight * 2.0) + 2.0,
                             CGRectGetWidth(mainViewBounds),
                             toolbarHeight)];

[self.view addSubview:toolbar];

[self createToolbarItems];

}

2 个答案:

答案 0 :(得分:1)

您是否检查过您的tableView是否与工具栏重叠?否则,看不出任何明显的问题。为表视图设置背景颜色以查看是否是这种情况。或者只是减少tableview的高度,看看是否能解决问题

答案 1 :(得分:0)

将表分隔符样式设置为None可以解决此问题。

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone