2012-07-26 37 views
-1

我想在我正在使用的iPhone應用程序之一的標籤上打印ascii值。我希望輸出是這樣的東西。我該怎麼做? enter image description here打印iPhone標籤中的星號符號

+2

爲什麼不把文本設置爲「客戶的名字*」? Asterisk在大多數QWERTY鍵盤上都是Shift-8。 – Polynomial 2012-07-26 13:37:12

回答

1
myLabel.text = @"Cutomer's First Name*"; 

編輯製作不同顏色的文字,你可以使用TTTAttributedLabel。 以下是密碼

TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(20, 20, 200, 200)]; 
NSString* text = @"Cutomer's First Name*"; 
[label setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^(NSMutableAttributedString *mutableAttributedString){ 
    //NSMutableAttributedString *mutableAttributedString; 
    NSRange whiteRange = [text rangeOfString:@"*"]; 
    if (whiteRange.location != NSNotFound) { 
     [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[UIColor redColor].CGColor range:whiteRange]; 
    } 
    return mutableAttributedString; 
}]; 
label.font = [UIFont fontWithName: @"Helvetica Neue" size: 10]; 
+0

非常感謝你的朋友:),我想要紅色的星號顏色。我該怎麼做? – Shantanu 2012-07-26 13:41:26

+0

爲了使星號變爲紅色,你必須帶上另一個標籤,字體顏色爲紅色,文本爲'*'。 – 2012-07-26 14:24:46

+0

[檢出這個例子](https://github.com/mattt/TTTAttributedLabel/tree/master/TTTAttributedLabelExample)希望它能幫助你。 – 2012-07-26 14:32:04