3

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.

Community
  • 1
  • 1
Michal
  • 15,429
  • 10
  • 73
  • 104

2 Answers2

5

This is complete example how to create and modify tint color, font color and font style in 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];
Denis Kutlubaev
  • 15,320
  • 6
  • 84
  • 70
4

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.

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498