Uifontdescriptor *bodyfontdescriptor = [Uifontdescriptor preferredfontdescriptorwithtextstyle:uifonttextstylebody] ; |
Self.textView.font = [Uifont fontwithdescriptor:bodyfontdescriptor size:0]; |
|
Self.textView.textColor = [Uicolor blackcolor]; |
Self.textView.backgroundColor = [Uicolor Whitecolor]; |
self.textView.scrollEnabled = YES; |
|
Let ' s modify some of the attributes of the attributed string. |
You can modify these attributes yourself to get a better feel for what they do. |
Note that the initial text was visible in the storyboard. |
nsmutableattributedstring *attributedtext = [[Nsmutableattributedstring alloc] initwithattributedstring: Self.textView.attributedText]; |
|
NSString *text = Self.textView.text; |
|
Find the range of each element to modify. |
Nsrange Boldrange = [text rangeofstring:nslocalizedstring (@ "bold", nil)]; |
Nsrange Highlightedrange = [text rangeofstring:nslocalizedstring (@ "highlighted", nil)]; |
Nsrange Underlinedrange = [text rangeofstring:nslocalizedstring (@ "underlined", nil)]; |
Nsrange Tintedrange = [text rangeofstring:nslocalizedstring (@ "tinted", nil)]; |
|
Add Bold. |
Uifontdescriptor *boldfontdescriptor = [Self.textView.font.fontDescriptor fontdescriptorwithsymbolictraits: Uifontdescriptortraitbold]; |
Uifont *boldfont = [Uifont fontwithdescriptor:boldfontdescriptor size:0]; |
[Attributedtext addattribute:nsfontattributename Value:boldfont Range:boldrange]; |
|
ADD highlight. |
[Attributedtext addattribute:nsbackgroundcolorattributename Value:[uicolor Aapl_applicationgreencolor] Range: Highlightedrange]; |
|
Add underline. |
[Attributedtext addattribute:nsunderlinestyleattributename value:@ (nsunderlinestylesingle) Range:underlinedRange] ; |
|
ADD Tint. |
[Attributedtext addattribute:nsforegroundcolorattributename Value:[uicolor Aapl_applicationbluecolor] Range: Tintedrange]; |
|
Add an image attachment. |
Nstextattachment *textattachment = [[Nstextattachment alloc] init]; |
UIImage *image = [UIImage imagenamed:@ "Text_view_attachment"]; |
Textattachment.image = image; |
Textattachment.bounds = CGRectMake (0, 0, image.size.width, image.size.height); |
|
nsattributedstring *textattachmentstring = [nsattributedstring attributedstringwithattachment:textattachment]; |
[Attributedtext appendattributedstring:textattachmentstring]; |
|
Self.textView.attributedText = Attributedtext; |