如何更改 Grouped UITableView 的边框颜色

发布于 2024-08-28 12:35:00 字数 1665 浏览 3 评论 0原文

这涉及 iPhoneOS-sdk-3.2

我很难更改分组 UITableView 的边框颜色。我现在可以很容易地更改单元格背景颜色、分隔符颜色、文本颜色,并且圆角可以正确剪辑,即使使用我选择的任何颜色突出显示也是如此。然而,尽管进行了许多不同的尝试,周围的边界仍然是令人恼火的灰色。

我已经阅读了通过 Google 可以找到的所有相关帖子,更不用说 stackoverflow 了。我见过 Mike Akers 的 UITableViewCell 裁剪的英雄 PITA 解决方案——这个问题在 iPhoneOS 3.0 上得到了解决,但它并没有帮助我解决边框问题。

我尝试了编程解决方案和基于 xib 的解决方案,并且都提供了相同的结果。

我将在下面分享编程版本:

我有一个 UIViewController 子类而不是 UITableViewController 子类来充当 UITableView 委托 - 我选择这条路线是因为我在 iPad 上编码,据报道 UITableViewController 接管了整个屏幕。我的 UIViewController 子类的 loadView 方法:

- (void) loadView {
  self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
  [self.view release];
  self.view.backgroundColor = [UIColor blackColor];

  // add and configure UITableView                                                                                     
  CGRect tableViewRect = CGRectMake(0., 0., 256., 768.);

  myTableView = [[UITableView alloc] initWithFrame:tableViewRect style:UITableViewStyleGrouped];

  // set the tableview delegate to this object and the datasource to the datasource which has already been set          
  myTableView.delegate = self;
  myTableView.dataSource = self;

  myTableView.sectionIndexMinimumDisplayRowCount = 1;

  myTableView.backgroundColor = [UIColor clearColor];
  myTableView.separatorColor = [UIColor whiteColor];
  myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

  myTableView.opaque = NO;

  // add the table view to our background view                                                                          
  [self.view addSubview:myTableView];
  [myTableView release];
}

This concerns iPhoneOS-sdk-3.2

I am having difficulty changing the border color of a grouped UITableView. I can change the cell background color, separator color, text color, quite easily now, and the rounded corners clip correctly, even when highlighted with whatever colors I have chosen. However the surrounding border remains infuriatingly gray despite many different attempts.

I have read all of the related posts I can find via Google, let alone stackoverflow. I have seen Mike Akers' heroic PITA solution for UITableViewCell clipping -- this problem is solved for iPhoneOS 3.0 and it did not help me with the border.

I have tried both a programmatic and xib-based solution and both provide the same results.

I will share the programmatic version below:

I have a UIViewController subclass rather than a UITableViewController subclass to act as a UITableView delegate -- I chose this route as I am coding on the iPad and UITableViewController reportedly takes over the whole screen. loadView method of my UIViewController subclass:

- (void) loadView {
  self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
  [self.view release];
  self.view.backgroundColor = [UIColor blackColor];

  // add and configure UITableView                                                                                     
  CGRect tableViewRect = CGRectMake(0., 0., 256., 768.);

  myTableView = [[UITableView alloc] initWithFrame:tableViewRect style:UITableViewStyleGrouped];

  // set the tableview delegate to this object and the datasource to the datasource which has already been set          
  myTableView.delegate = self;
  myTableView.dataSource = self;

  myTableView.sectionIndexMinimumDisplayRowCount = 1;

  myTableView.backgroundColor = [UIColor clearColor];
  myTableView.separatorColor = [UIColor whiteColor];
  myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

  myTableView.opaque = NO;

  // add the table view to our background view                                                                          
  [self.view addSubview:myTableView];
  [myTableView release];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜血染红嫁衣 2024-09-04 12:35:00

我找到了解决方案。此行为似乎是 iPhoneOS 3.2 特有的,因为 Apple 在 iPhoneOS 3.2 中为 UITableView 添加了 backgroundView 属性。

我尝试了 [myTableView.backgroundView removeFromSuperView] 并且 UITableView 只是将其替换为另一个。

相反,我的解决方案是添加:

myTableView.backgroundView.hidden = YES;

I found a solution. This behavior does appear to be iPhoneOS 3.2 specific as Apple added a backgroundView property for UITableView in iPhoneOS 3.2.

I tried [myTableView.backgroundView removeFromSuperView] and UITableView just replaced it with another.

Instead, my solution was to add:

myTableView.backgroundView.hidden = YES;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文