gpt4 book ai didi

ios - UIRefreshControl attributedTitle 多行

转载 作者:可可西里 更新时间:2023-11-01 05:30:25 26 4
gpt4 key购买 nike

是否可以在 UIRefreshControl 标题中使用多行?每当我将\n 添加到 NSAttributedString 时,只会显示第一行。我正在尝试设置标题,并在下一行添加更多文本。那么是否有在 UIRefreshControl 中使用两行文本的解决方法?

这是当前代码,其中仅显示“Title Here”:

self.refreshControl = [[UIRefreshControl alloc] init];

NSString *title = @"Title Here";
NSString *subText = @"Subtext Here";
NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",title,subText]];

[attString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica" size:20.0f] range:NSMakeRange(0, [title length])];
[attString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica" size:14.0f] range:NSMakeRange([title length],[subText length])];

[attString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, [title length])];
[attString addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange([title length], [subText length])];

self.refreshControl.attributedTitle = attString;

最佳答案

这里有一个tricky方法:在 UIRefreshControl 中找到 UILabel 并设置 numberOfLines = 0。

UILabel *titleLabel = [[[[self.refreshControl subviews] firstObject] subviews] lastObject];
if (titleLabel) {
titleLabel.numberOfLines = 0;

NSString title = @"Pull to Refresh.\nUpdated Time: 09:30"; // \n for new line.
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:title];
}

关于ios - UIRefreshControl attributedTitle 多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16146160/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com