【发布时间】:2015-04-23 10:50:31
【问题描述】:
我有一个自定义 UITableViewCell 正在 tableView 中显示。这个 UITableViewCell 是从一个 nib 文件生成的。 UITableViewCell 中有一个 UILabel。下面给出了代码。显然我试图将字体大小减小到固定大小,但似乎没有任何效果。这是我目前正在做的设置字体大小的操作。
在 UITableViewCell(这是附加到笔尖的 .m 文件)中,这是我所做的
- (void)awakeFromNib
{
UIFont *myFont = [ UIFont fontWithName: @"Arial" size: 4.0 ];
self.LabelMyLabel.font = myFont;
}
这就是 TableView 的创建方式
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *TransferIdentifier = @"TransferTableItem";
FileTransferTableCell *cell = [tableView dequeueReusableCellWithIdentifier:TransferIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FileCustomTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
//Set the text in the UITableViewCell here
cell.textLabel.text = [self.MyArray objectAtIndex:indexPath.row];
return cell;
}
如果有人能帮我弄清楚为什么我的 textsize 总是恒定的,我将不胜感激(我还在界面生成器中减小了 UITableViewCell 中标签的字体大小)?
【问题讨论】:
-
尝试将您的代码移动到
viewDidLoad而不是awakeFromNib。 -
@Wongzigii 表格单元格中没有
viewDidLoad。 -
您是否仔细检查了您的笔尖连接?是不是叫 textLabel 的标签?
-
是的,我有 - 我也重做了它们,但它是一样的
-
你这里有一个严重的不匹配。您通过说
cell.textLabel.text设置文本,但通过说self.LabelMyLabel.font设置字体。这些不可能都是正确的。标签是textLabel还是LabelMyLabel?
标签: ios objective-c iphone uitableview