I have created a string that depends on what the user inputs into the textfield:
NSString *book = [[NSString alloc] initWithFormat:@"%@%@", bookTitle.text, afterbook];
Then this string is part of a bigger string:
NSString *msg = [[NSString alloc] initWithFormat:@"%@%@%@%@%@%@%@%@%@%@%@%@%@%@", lastname,
firstname, secondfirstname, secondlastname, thirdfirstname, thirdlastname, book, numb, volume, pubcity, pubcomp, year, pages, print];
开发者_Python百科
I want to format the NSString *book so that it is italics. I don't care about displaying it on the view, but I do want to be able to copy this to the clipboard so I can paste it to a program like Pages on the iPad.
NSStrings are plain text. They have no notion of styling, fonts, colors, or anything else that only becomes relevant when drawing the string.
You need to either use UIKit to draw each substring the way you want it, or create an NSAttributedString, use the Core Text string attributes on the appropriate range to apply the italics, and use Core Text to draw the whole attributed string.
You cannot format an NSString
to be italicised.
Source
精彩评论