gpt4 book ai didi

objective-c - 如何在 UIRefreshControl 中使用 NSAttributedString

转载 作者:搜寻专家 更新时间:2023-10-30 19:55:04 24 4
gpt4 key购买 nike

我在 this post 中找到了示例对于 NSAttributedString。我的问题是 - 是否有任何提示,如何将它用于 UIRefreshControl 类

来自上面的帖子:

NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"firstsecondthird"];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(11,5)];

UIRefreshControl 是否自动调用属性?

编辑:

我知道如何设置它,我想知道除了“只是”格式化标签之外它是否还有其他用途 - UIRefresherControl 是否能够显示两个 字符串?一个是拉之前,一个是拉之后?当我看到我不能输入“普通”字符串时,我一开始就是这么想的。

最佳答案

这是如何在 UIRefreshControl 中创建和修改色调颜色、字体颜色和字体样式的完整示例:

_refreshControl = [[UIRefreshControl alloc] init];
_refreshControl.tintColor = [UIColor blackColor];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"Pull to Refresh"];
NSRange fullRange = NSMakeRange(0, [string length]);
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:fullRange];
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Georgia" size:17] range:fullRange];
[_refreshControl setAttributedTitle:string];
[_refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
[self setRefreshControl:_refreshControl];

关于objective-c - 如何在 UIRefreshControl 中使用 NSAttributedString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12932238/

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