Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:44:08+00:00 2026-06-14T19:44:08+00:00

I am trying to allow users the ability to set text they will type

  • 0

I am trying to allow users the ability to set text they will type as underline, without having text currently selected. This is for an iOS 6 app, entering text in a UITextView. It will be saved as an NSAttributedString. Bold and italic work fine. Something about underline is keeping it from working.

UITextView *textView = [self noteTextView];
NSMutableDictionary *typingAttributes = [[textView typingAttributes] mutableCopy];
[typingAttributes setObject:[NSNumber numberWithInt:NSUnderlineStyleSingle] forKey:NSUnderlineStyleAttributeName];
NSLog(@"attributes after: %@", typingAttributes);
[textView setTypingAttributes:typingAttributes];
NSLog(@"text view attributes after: %@", [textView typingAttributes]);

My initial log statement indicates it is set to underline:

attributes after: {
    NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
    NSFont = "<UICFFont: 0xa9c5e30> font-family: \"Verdana\"; font-weight: normal; font-style: normal; font-size: 17px";
    NSKern = 0;
    NSStrokeColor = "UIDeviceRGBColorSpace 0 0 0 1";
    NSStrokeWidth = 0;
    NSUnderline = 1;
}

But the log statement immediately after doesn’t show an nsunderline attribute. Removing the textView setTypingAttributes line has no affect.

text view attributes after: {
    NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
    NSFont = "<UICFFont: 0xa9c5e30> font-family: \"Verdana\"; font-weight: normal; font-style: normal; font-size: 17px";
    NSKern = 0;
    NSStrokeColor = "UIDeviceRGBColorSpace 0 0 0 1";
    NSStrokeWidth = 0;
}

I’m stumped why I have it working for bold and italic, but not underline. Also why it seems to initially get the attribute, then forget it. Please share any insight you may have. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:44:10+00:00Added an answer on June 14, 2026 at 7:44 pm

    I think you’ve found a bug, or at least some undocumented behavior. If I set the typing attributes to red, I can do it:

    -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
            replacementString:(NSString *)string {
        NSDictionary* d = textField.typingAttributes;
        NSLog(@"%@", d);
        NSMutableDictionary* md = [NSMutableDictionary dictionaryWithDictionary:d];
        // md[NSUnderlineStyleAttributeName] = @(NSUnderlineStyleSingle);
        md[NSForegroundColorAttributeName] = [UIColor redColor];
        textField.typingAttributes = md;
        return YES;
    }
    

    With that code, all the user’s new typing comes out red. But if I uncomment the commented line, trying to add underlining to the typing attributes, it breaks the whole thing – I don’t get underlining, and I don’t get red coloring either!

    The answer to the other part of your question, though, is documented. You have to do it the way I’m doing it, reasserting the typing attributes as the user types, because, as the documentation clearly states, “When the text field’s selection changes, the contents of the dictionary are cleared automatically” (that’s the “forgetting” you asked about).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to allow users to vote on threads without having to sign in/up
Im trying to allow users to login to a website by verifying if they
I'm trying to develop a system that will allow users to update local, offline
I'm trying to create a dialog which will allow users to upload an image.
I am trying to create a small web app that will allow users to
I am trying allow users to copy and paste my text content that sits
I am trying to come up with a UI which will allow users of
I am trying to add an ability to allow users of a wvb app
So I'm trying to add some ability to my project to allow user-defined properties
I'm trying to allow users to register on my web application via Facebook. As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.