Question

In my application I want to write 15 Font Size Attributed Text (like Bold, Italic, Underline) in One UITextView.

And Want to get that same text written in 35 Font Size Attributed Text in Another UITextView.

I did All the Attribute text Write task in UITextView.

But don't get how to write same text in another UITextView in same Time with Different Font Size.
I need to define different NSMutableParagraphStyle For both the UITextView.

My Code For just Bold Text is

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
 UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
    NSDictionary *attributes = @{NSFontAttributeName :font};
    [txtView1 setTypingAttributes:attributes];

 UIFont *font35 = [UIFont fontWithName:@"Helvetica-Bold" size:35];
    NSDictionary *attributes35 = @{NSFontAttributeName :font35};
    [txtView2 setTypingAttributes:attributes35];

NSMutableAttributedString *mat = [txtViewOfNotes.attributedText mutableCopy];
            [mat addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range:NSMakeRange (range.location-1, 1)];
txtView1.attributedText = mat;

NSMutableAttributedString *mat = [txtViewOfNotes.attributedText mutableCopy];
            [mat addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range:NSMakeRange (range.location-1, 1)];
txtView2.attributedText = mat;


}

Any kind of Idea, code, or tutorial will be great Help.

Was it helpful?

Solution

I think you need to add the attributes and then change the text for both textViews. So, use as the following :

NSMutableAttributedString *title = [[NSMutableAttributedString alloc]initWithString:text];
UIFont *font = [UIFont fontWithName:@"Arial" size:15];
[title addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, title.length)];
titleView1.attributedText = title;

 UIFont *font = [UIFont fontWithName:@"Arial" size:35];
[title addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, title.length)];
titleView1.attributedText = title;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top