Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewCell don';当使用较大的文本时,不要更改布局_Ios_Uitableview_Accessibility_Dynamic Type Feature - Fatal编程技术网

Ios UITableViewCell don';当使用较大的文本时,不要更改布局

Ios UITableViewCell don';当使用较大的文本时,不要更改布局,ios,uitableview,accessibility,dynamic-type-feature,Ios,Uitableview,Accessibility,Dynamic Type Feature,我有一个UITableView,如下所示: 当用户更改iOS文本大小设置时,布局将更改 布局会发生变化,细节标签会被压到标题下,而披露指标会变得非常大。标准单元布局和自定义单元布局以及我自己的UILabel子视图都会出现这种情况 我还没有准备好支持动态类型,所以有没有办法不允许iOS更改我的uitableviewcell的布局?已经为iOS做了很多事情来帮助表视图单元格中的动态类型实现⟹ 比如说 我在一个空白项目中重现了最初的问题,如下所示: 由于没有额外的代码,并且仅由于iOS本机实

我有一个
UITableView
,如下所示:

当用户更改iOS文本大小设置时,布局将更改

布局会发生变化,细节标签会被压到标题下,而披露指标会变得非常大。标准单元布局和自定义单元布局以及我自己的
UILabel
子视图都会出现这种情况


我还没有准备好支持动态类型,所以有没有办法不允许iOS更改我的
uitableviewcell
的布局?

已经为iOS做了很多事情来帮助表视图单元格中的动态类型实现⟹ 比如说

我在一个空白项目中重现了最初的问题,如下所示:

由于没有额外的代码,并且仅由于iOS本机实现,请注意:

  • 当到达第一个可访问性步骤时,标签会重新排序
  • 系统附件元件尺寸根据使用的动态类型而变化
  • 有一个自动调整行高的功能
[…]有没有办法不允许iOS更改我的UITableViewCells的布局

解决方案可能会导致创建您自己的自定义表视图单元格,如下所示:

class MyTableViewCell: UITableViewCell {

    @IBOutlet weak var myTitle: UILabel!
    @IBOutlet weak var myDetail: UILabel!

    static let reuseIdentifier = "myReuseIdentifier"

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUpElementsAndConstraints()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setUpElementsAndConstraints()
    }

    private func setUpElementsAndConstraints() {
        //Custom your labels and their constraints in here.
        //For the demo, everything is hard coded within the Interface Builder.
    }
}
  • 将属性
    adjustsFontForContentSizeCategory
    为false的标签添加到标签中,以便进行修改

  • 创建您自己的“V形图像”,该图像的大小不会调整为系统图像:

     override func tableView(_ tableView: UITableView,
                             cellForRowAt indexPath: IndexPath) -> MyTableViewCell {
    
         let cell = tableView.dequeueReusableCell(withIdentifier: MyTableViewCell.reuseIdentifier,
                                                  for: indexPath) as! MyTableViewCell
    
         let accessoryImageFrame = CGRect(x: 0.0, y: 0.0,
                                          width: 40.0, height: 40.0)
         let accessoryImageView = UIImageView(frame: accessoryImageFrame)
         accessoryImageView.image = UIImage(named: "MyChevron")
    
         cell.accessoryView = accessoryImageView
    
         return cell
     }
    
  • 在表视图中定义静态行高度:

     override func tableView(_ tableView: UITableView,
                             heightForRowAt indexPath: IndexPath) -> CGFloat { return 50.0 }
    
  • 不要忘记设置您的约束,这些约束可能会根据文本大小设置进行更新,这要归功于该方法。。。即使您还不想使用动态类型功能。