Search code examples
objective-cios6nsattributedstringuirefreshcontrol

How to use NSAttributedString in UIRefreshControl


I found example in this post for NSAttributedString. My question is - are there any hints, how to use it for UIRefreshControl class?

From the post above:

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)];

Are the attributes called by the UIRefreshControl automatically?

EDIT:

I know how to set it, I want to know whether it serves any other purpose then "just" formatted label - is the UIRefresherControl able to display TWO strings? One before it has been pulled and one after it has been pulled? That's what I thought at first when I saw I can't put in "ordinary" string.


Solution

  • Well, seeing as how UIRefreshControl has an attributedTitle property that takes an NSAttributedString, and seeing as how NSMutableAttributedString is a subclass of NSAttributedString, you would do:

    [myRefreshControl setAttributedTitle:string];
    

    is the UIRefresherControl able to display TWO strings?

    No. But you can try putting in an attributed string with multiple lines, or perhaps different paragraph styles (so one part could be left aligned, and another right aligned, for example).

    One before it has been pulled and one after it has been pulled?

    No. It is up to you to change the attributed title of the refreshControl according to your own application's logic.