【问题标题】:IOS 8 Dynamic Type with Static TableView Cell - Basic and Subtitle带有静态 TableView 单元的 IOS 8 动态类型 - 基本和字幕
【发布时间】:2014-10-11 11:28:40
【问题描述】:

在设置中更改文本大小并返回应用程序后,Basic 和 Subtitle 类型的静态单元格并留空,直到您离开视图或重新加载应用程序。自定义静态单元格保留其文本。

易于复制。

创建一个单视图应用,将 UIViewController 替换为 UiTableViewController。 将内容从动态单元格更改为静态单元格。

设置样式单元格 0 = 自定义,单元格 1 = 基本和单元格 2 = 字幕

为所有人连接属性

@property (weak, nonatomic) IBOutlet UILabel *customCell;
@property (weak, nonatomic) IBOutlet UILabel *basicCell;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *subTitleLabel;

将以下内容添加到 viewDidLoad

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self selector:@selector(updateInterfaceForDynamicTypeSize)      name:UIContentSizeCategoryDidChangeNotification object:nil];


self.customCell.text = @"Custom Cell";
self.basicCell.text = @"Basic Cell";
self.titleLabel.text = @"My Title";
self.subTitleLabel.text = @"My Sub Title";

添加以下方法

-(void)updateInterfaceForDynamicTypeSize {
UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
self.customCell.font = font;
self.basicCell.font = font;
self.titleLabel.font = font;
font = [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
self.subTitleLabel.font = font;
[self.tableView reloadData];
}

运行应用程序 - 然后转到设置并更改文本大小。 返回应用程序,仅显示自定义单元格内容。

IOS 7 不是这种情况。我在这里遗漏了什么还是这是一个错误?

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    在情节提要中配置您的单元格以使用自定义类而不是默认的UITableViewCell

    简单的自定义单元实现如下:

    // DynamicTypeResistantCell.h
    #import <UIKit/UIKit.h>
    @interface DynamicTypeResistantCell : UITableViewCell
    
    @end
    
    
    // DynamicTypeResistantCell.m
    @implementation DynamicTypeResistantCell
    - (void)_systemTextSizeChanged
    {
        // don't call super!
    }
    @end
    

    然后您可以安全地使用 Basic 和 Subtitle 样式,并且单元格在动态类型大小更改后保留其内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-02
      • 1970-01-01
      • 2018-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多