Ios 为表视图的内容提供动态类型
如果用户在iPhone设置中选择了另一种字体大小,我试图使表视图的内容能够更改其字体大小。我通过以下代码实现了它:Ios 为表视图的内容提供动态类型,ios,Ios,如果用户在iPhone设置中选择了另一种字体大小,我试图使表视图的内容能够更改其字体大小。我通过以下代码实现了它: //(Start)Updating font size UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; cell.textLabel.font = font; //(END) 但它不会自动更新表视图的内容,我需要单击它来执行更改。我很确定我的解决方案不是正确的,所以你能告诉我什么是实现我
//(Start)Updating font size
UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
cell.textLabel.font = font;
//(END)
但它不会自动更新表视图的内容,我需要单击它来执行更改。我很确定我的解决方案不是正确的,所以你能告诉我什么是实现我目标的正确方法吗
以下是完整的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath
{
static NSString * kGroupsTableViewCell = @"kGroupsTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kGroupsTableViewCell];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kGroupsTableViewCell];
}
TGroup * group = [self.groupsArray objectAtIndex:indexPath.row];
cell.textLabel.text = group.name;
//(Start)Updating font size
UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
cell.textLabel.font = font;
//(END)
if ([self.selectedGroups containsObject:group.uid]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
您只需要订阅大小更改通知并重新加载表
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self.tableView
selector:@selector(reloadData)
name:UIContentSizeCategoryDidChangeNotification
object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self.tableView];
}