[英]iOS7 - How to underline a UITextField
我已經看過(並嘗試了代碼片段) 這個問題 ,但是想知道iOS7中是否出現了問題? 我更有可能做錯了事。
我的代碼如下:
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];
我收到此編譯錯誤:
***由於未捕獲的異常“ NSInvalidArgumentException”而終止應用程序,原因:“ NSConcreteMutableAttributedString initWithString ::無值”
如果我使用純文本
self.titleLabel.text = [NSString stringWithFormat:@"%@", tempString1];
它工作正常。 任何幫助表示贊賞。
我認為您的字典currentMemory為鍵“ title”返回nil,而nil導致init異常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.