2013-04-22 69 views
2

如果我在UILabel中有一段文字,我需要在文字中間顯示註冊商標,該如何實現?我真的不想使用圖像視圖。我有點想重寫drawRect或者......但還沒弄明白。如何在上標中提供註冊商標

謝謝!

+4

使用Unicode? ™ - – 2013-04-22 14:35:32

+0

@MattBall,「™」是商標標誌。註冊*商標的符號是註冊符號「®」U + 00AE。 – 2013-04-22 16:03:06

+0

@ JukkaK.Korpela我不清楚OP的實際含義。無論哪種方式,建議立場。 – 2013-04-22 16:10:55

回答

2

這是馬特建議的unicode。這只是你如何在NSLocalizedString中使用它。 Unicode代表symbols。在處理字符串以支持使用語言文件的多種語言時,推薦使用NSLocalizedStrings。

someText.text = NSLocalizedString(@"iPhone\u2122",nil); 
+0

請解釋。這是什麼?爲什麼使用它? – Popeye 2013-04-22 14:39:08

+0

這是馬特建議的unicode。這只是你如何在NSString中使用它。 http://en.wikipedia.org/wiki/List_of_Unicode_characters – 2013-04-22 14:40:11

+3

不需要'stringWithFormat'。請不要使用'stringWithFormat',除非字符串實際上具有需要用值替換的格式說明符。 – rmaddy 2013-04-22 14:41:09

5

可以使用內NSString任何地方的Unicode字符序列\u2122,它會適當地由UILabel呈現:

someLabel.text = @"This is some text about a Trademarked Name\u2122"; 
+5

或者你可以使這個可讀並直接鍵入'?'字符。 'someLabel.text = @「這是一些關於商標名稱的文字」;' – rmaddy 2013-04-22 14:43:06

2

使用性質註冊SIGN「®」 U + 00AE(書面內如果不能直接鍵入,則爲\00AE)。請注意,它的外觀因字體而異:一般來說,它看起來像上標,但這不是要求,有些字體在文本基線上顯示,而「R」大約是常規「R」大小的一半,因此相當可讀。

+0

謝謝,但我正在尋找一種方法以上標以編程方式顯示符號 - 並非真的想要使用多個標籤...... – Koolala 2013-05-06 14:07:32

2

從iOS6中我們可以使用NSAttributedString的概念。請參閱下面的代碼片段。如果有人已經意識到這一點,請忽略。

static NSString *html = 
    @"<html>" 
    " <body>Here is trademark &reg; </i></body>" 
    "</html>"; 

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 280, 300, 200)]; 
    NSError *err = nil; 
    label.attributedText = 
    [[NSAttributedString alloc] 
    initWithData: [html dataUsingEncoding:NSUTF8StringEncoding] 
    options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } 
    documentAttributes: nil 
    error: &err]; 
    if(err) 
     NSLog(@"Unable to parse label text: %@", err); 
相關問題