iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 归因于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;  

    }
@H_404_43@

大佬总结

以上是大佬教程为你收集整理的ios – 归因于TableView Cell上无效的文本全部内容,希望文章能够帮你解决ios – 归因于TableView Cell上无效的文本所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。