iOS7 - How to underline a UITextField

810 Views Asked by At

I have looked at (and tried the code snippets) this question, but wonder if something has come up in iOS7? More likely, I'm doing something wrong.

My code is as follows:

import <CoreText/CoreText.h>

    NSString *tempString1 = [currentMemory valueForKey:@"title"];

    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:tempString1];
        [attString addAttribute:(NSString*)kCTUnderlineStyleAttributeName
                    value:[NSNumber numberWithInt:kCTUnderlineStyleSingle]
                    range:(NSRange){0,[attString length]}];
        self.titleLabel.attributedText = attString;
        self.titleLabel.textColor = [UIColor whiteColor];

I'm getting this compile error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteMutableAttributedString initWithString:: nil value'

If I use plain text

self.titleLabel.text = [NSString stringWithFormat:@"%@", tempString1];

it works fine. Any help appreciated.

1

There are 1 best solutions below

1
On

I think your dictionary, currentMemory, is returning nil for the key "title" and that nil is causing the exception in init.