4

it's a bit of tricky question but i hope some can help me

i want to have a label with custom font in my ios app and if i copied the text in it and paste it any where else .. in another app maybe .. that it pasted with the same font..

i know it's doable i found and app did it before .. but i have no idea how is that!

i used this code but it just copy a text from label

NSString *copyStringverse =     [NSString stringWithFormat:@"%@",self.label.text];
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:copyStringverse];

any idea?

Mohamed Emad Hegab
  • 2,665
  • 6
  • 39
  • 64
  • 1
    see http://stackoverflow.com/questions/12789507/copy-text-with-formatting-ios-6-nsattributedstring-to-pasteboard – Rachel Gallen May 26 '13 at 12:32
  • there is also an article about it here http://support.apple.com/kb/PH3397?viewlocale=en_US – Rachel Gallen May 26 '13 at 12:35
  • @RachelGallen i used that lines [self.noteTextView select:self]; self.noteTextView.selectedRange = NSMakeRange(0, [self.noteTextView.text length]); [[UIApplication sharedApplication] sendAction:@selector(copy:) to:nil from:self forEvent:nil]; [self.noteTextView resignFirstResponder]; and i removed what i used above .. but nothing changed.. how should it work – Mohamed Emad Hegab May 26 '13 at 12:51
  • @Mohammed Emad Hegab I'm at a loss then. thought that would work. – Rachel Gallen May 26 '13 at 12:54
  • it should work i just don't know how :) – Mohamed Emad Hegab May 26 '13 at 13:07

1 Answers1

0

Try using NSAttributedString instead of NSString

Hope this will work for you.

Prashant Nikam
  • 2,253
  • 4
  • 17
  • 29
  • ok it worked .. but if you can give me a hint about how to set this attributedString into UIPasteboard – Mohamed Emad Hegab May 28 '13 at 10:46
  • 1
    you cannot use [pb setString:attributedstring]; to set NSAttributedString here as it only accept NSString. Instead try this [pb setValue:attributedstring forKey:@"Mystring"]; This might work, give it a try. – Prashant Nikam May 28 '13 at 11:30
  • well it gives me error [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key pb. – Mohamed Emad Hegab May 29 '13 at 06:54
  • I don't think there is any way to set NSAttributedString in UIPasteboard because it accepts only few datatypes like string,image,URL,Color. So I would suggest you to use NSString and then use string and color setters of pasteboard i.e. [pb setString:myString]; [pb setColor:myStringColor]; But again there is no way to pass the size of string. – Prashant Nikam May 29 '13 at 09:24
  • 1
    i don't want size i just want the fonts any way i'll try this and tell you – Mohamed Emad Hegab May 30 '13 at 07:25