【问题标题】:DetailView Controller Title Font IssueDetailView 控制器标题字体问题
【发布时间】:2014-07-06 04:27:07
【问题描述】:

我有一个从 UITableView 控制器推送的 DetailView 控制器。我要做的是在从 UITableViewController 推送标题时更改标题的字体。我将向您展示我正在执行的 segue 的代码行。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//push segue identifier 'showArrayDetail'
if ([[segue identifier] isEqualToString:@"ShowDetail"])
{
    NSString *object = nil;

    [[segue destinationViewController] setDetailLabelContents:object];

    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    DetailViewController *destViewController = segue.destinationViewController;
    destViewController.climbName = climbs[indexPath.row];
    destViewController.title = [NSString stringWithFormat:@"%@ Details", destViewController.climbName];

    destViewController.title = [UIFont fontWithName:@"Chalkduster" size:17];
}

}

最后一行是我试图更改字体的地方,它给了我这个警告:

FourthTableViewController.m:134:34: Incompatible pointer types assigning to 'NSString *' from 
'UIFont *

有没有办法解析标题或解决这个问题?在我的 UITableViews 等中更改我的字体时,我正在执行相同的方法。它只是不喜欢你对标题执行此操作。

谢谢

【问题讨论】:

  • 属性标题是什么? UILabel 还是 NSString?
  • 您不能将字体设置为 NSString,只能设置为 NSAttributedString 或任何具有 font 属性的字体。下面有一个涉及属性字符串的答案

标签: ios objective-c uitableview detailsview uifont


【解决方案1】:

您实际上无法更改这样的字体。您刚刚创建了 UIFont 的新实例,而不是 NSString 实例。您需要阅读更多关于属性字符串的内容here。示例:

NSFont *font = [NSFont fontWithName:@"Palatino-Roman" size:14.0];
NSDictionary *attrsDictionary =
        [NSDictionary dictionaryWithObject:font
                                    forKey:NSFontAttributeName];
NSAttributedString *attrString =
    [[NSAttributedString alloc] initWithString:@"strigil"
            attributes:attrsDictionary];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 2011-01-04
    • 2010-12-09
    • 2011-10-28
    • 2017-09-18
    相关资源
    最近更新 更多