[英]attributed text not working on TableView Cell
尝试在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;
}
您需要创建一个NSMutableAttributedString字符串然后分配它。 因此,有关详细信息,请参阅此示例。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
NSMutableAttributedString *str=[[NSMutableAttributedString alloc] initWithString:[infoCells objectAtIndex:indexPath.row]];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:50] range:NSMakeRange(0, str.length)];
cell.textLabel.attributedText = str;
//cell.textLabel.font = [UIFont fontWithName:@"Adobe Arabic" size:20];
return cell;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.