【发布时间】:2013-12-05 10:11:32
【问题描述】:
尝试在 TabelViewCell 上使用不同的字体和字体大小,但它不起作用。
这是我尝试过的:
cell.textLabel.attributedText = [infoCells objectAtIndex:indexPath.row];
此代码使应用程序崩溃
然后我尝试了这个:
cell.textLabel.text = [infoCells objectAtIndex:indexPath.row];
现在一切正常,但字体和字体大小没有改变。
以下是我的应用程序中的更多代码:
- (void)viewDidLoad
{
[super viewDidLoad];
infoCells = [[NSMutableArray alloc] initWithCapacity:2];
[infoCells addObject:@"DOI"];
[infoCells addObject:@"WIS?"];
[infoCells addObject:@"اللَّهُمَّ إِنِّي أَسْتَخِيرُكَ بِعِلْمِكَ وَأَسْتَقْدِرُكَ بِقُدْرَتِكَ"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.attributedText = [infoCells objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont fontWithName:@"Adobe Arabic" size:20];
return cell;
}
【问题讨论】:
-
您的数组
infoCells不包含任何NSAttributedString对象。只是普通的NSString对象。 -
我如何使字符串属性化?
-
您创建
NSAttributedString对象并提供正确的属性。 -
创建 NSAttributedString 而不是 NSString 。
标签: ios iphone objective-c ios7 textkit