在分组的 UITableView 中使用 viewForHeaderInSection 替换默认 header
replace default header using viewForHeaderInSection in a grouped UITableView
我想将 uiactivityindicator 恰好放在 UITableView 中的部分标题之后。我正在尝试使用 (table 的第一部分)
viewForHeaderInSection。这与原生 Settings.app
中 WiFi 设置中的旋转器视图类似
代码没有给出我想要的
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if( section == 0 ) {
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 16.0)];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 10.0, 320.0, 16.0)];
headerLabel.backgroundColor = [tableView backgroundColor];
headerLabel.text = NSLocalizedString(@"Choose a Network...", @"Choose a Network...");
headerLabel.font = [UIFont boldSystemFontOfSize:16.0];
headerLabel.textColor = [UIColor colorWithRed:61.0/255.0 green:77.0/255.0 blue:99.0/255.0 alpha:1.0];
headerLabel.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.65];
headerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
[header addSubview:headerLabel];
self.searchNetworks.frame = CGRectMake(190.0, 18.0, 0.0, 0.0);
[header addSubview:self.searchNetworks];
return header;
}
return nil;
}
我希望我的自定义视图准确定位在默认视图的位置。我该怎么做?
您当前拥有的用于放置 activity 指标的代码没有问题并且可以使用。我看到的唯一问题是,如果您希望它始终可见,您没有明确地将 hidesWhenStopped
设置为 NO
。否则,您必须调用 startAnimating
使其可见(并以任何一种方式调用它以使其具有动画效果)。
此外,根据您tableView
的颜色,您可能看不到指示器。如果是这种情况,您可以更改 tableView
的 backgroundColor
(如果您使用的是分组 tableView
),或 [=28= 部分的 backgroundColor
],或 activity 指标的 color
属性。
这些是我的建议!让我知道是否有帮助。
For reference:
You control when an activity indicator animates by calling the startAnimating and stopAnimating methods. To automatically hide the activity indicator when animation stops, set the hidesWhenStopped property to YES.
Starting in iOS 5.0, you can set the color of the activity indicator by using the color property.
我想将 uiactivityindicator 恰好放在 UITableView 中的部分标题之后。我正在尝试使用 (table 的第一部分) viewForHeaderInSection。这与原生 Settings.app
中 WiFi 设置中的旋转器视图类似代码没有给出我想要的
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if( section == 0 ) {
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 16.0)];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 10.0, 320.0, 16.0)];
headerLabel.backgroundColor = [tableView backgroundColor];
headerLabel.text = NSLocalizedString(@"Choose a Network...", @"Choose a Network...");
headerLabel.font = [UIFont boldSystemFontOfSize:16.0];
headerLabel.textColor = [UIColor colorWithRed:61.0/255.0 green:77.0/255.0 blue:99.0/255.0 alpha:1.0];
headerLabel.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.65];
headerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
[header addSubview:headerLabel];
self.searchNetworks.frame = CGRectMake(190.0, 18.0, 0.0, 0.0);
[header addSubview:self.searchNetworks];
return header;
}
return nil;
}
我希望我的自定义视图准确定位在默认视图的位置。我该怎么做?
您当前拥有的用于放置 activity 指标的代码没有问题并且可以使用。我看到的唯一问题是,如果您希望它始终可见,您没有明确地将 hidesWhenStopped
设置为 NO
。否则,您必须调用 startAnimating
使其可见(并以任何一种方式调用它以使其具有动画效果)。
此外,根据您tableView
的颜色,您可能看不到指示器。如果是这种情况,您可以更改 tableView
的 backgroundColor
(如果您使用的是分组 tableView
),或 [=28= 部分的 backgroundColor
],或 activity 指标的 color
属性。
这些是我的建议!让我知道是否有帮助。
For reference:
You control when an activity indicator animates by calling the startAnimating and stopAnimating methods. To automatically hide the activity indicator when animation stops, set the hidesWhenStopped property to YES.
Starting in iOS 5.0, you can set the color of the activity indicator by using the color property.