Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.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字体大小数组与字符串_Ios_Xcode_Swift_Ios8 - Fatal编程技术网

Ios UITableViewCell字体大小数组与字符串

Ios UITableViewCell字体大小数组与字符串,ios,xcode,swift,ios8,Ios,Xcode,Swift,Ios8,最后,我在表格中创建了一个原型单元格,并在其中添加了两个标签的标签。当我按标签检索标签,并为其指定硬编码文本时,它正确显示。但是,当我从NSMutableArray中获取值并尝试显示它时,它会显示出来,但字体会更大。标签上的其他样式得到尊重,例如颜色 这是我的密码: func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {

最后,我在表格中创建了一个原型单元格,并在其中添加了两个标签的标签。当我按标签检索标签,并为其指定硬编码文本时,它正确显示。但是,当我从NSMutableArray中获取值并尝试显示它时,它会显示出来,但字体会更大。标签上的其他样式得到尊重,例如颜色

这是我的密码:

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

    var lblTitle:UILabel = cell.viewWithTag(7) as UILabel
    var lblAmount:UILabel = cell.viewWithTag(8) as UILabel

    lblTitle.text = reportData[indexPath.row] as NSString //ignores my label font size of 13, but preserves the color?? 
    lblAmount.text = "$5151.55" //HARD CODED VALUE - respects my font size of 13

    return cell
}
你知道为什么它会在标签上保留颜色样式吗?但是每当我从上面的nsmutablearray检索值时,它使用的标准字体大小比我在标签上设置的要大得多


我很想听到一些关于我考虑/做得不对的意见。我想知道字体是否在某种程度上被拉伸了,但这并不能解释为什么它适用于硬编码字符串。

一个奇怪的错误。我想说的第一件事是,我不太熟悉Swift语言的语法,但对Objective C很在行。 解决方案建议:在获得UILabels的引用后,只需编写代码以编程方式设置所需的字体大小。可能这可以解决您的问题,可以帮助您调试问题

您可以这样做:

label.font = UIFont(name: label.font.fontName, size: 20)

这将使用相同的字体。20当然可以是您想要的任何大小。

如果反转哪个标签是硬编码的硬编码lblTitle文本,并使用lblAmount文本的数组值,您会得到相同的结果吗?