部分的に太字の NSMutableAttributedString を作成したいメソッドを作成しました。ただし、必要なデータを返すために呼び出すのに問題があります。
これは私がコードを実装した方法です
//.h
// creates bold portion of the labels in toolbar
- (NSMutableAttributedString *)createBoldString:(NSString *)labelString intRangeA:(int)rangeA intRangeB:(int)rangeB;
//.m
- (NSMutableAttributedString *)createBoldString:(NSString *)labelString intRangeA:(int)rangeA intRangeB:(int)rangeB {
// iOS6 and above : Use NSAttributedStrings
const CGFloat fontSize = 12;
UIFont *boldFont = [UIFont boldSystemFontOfSize:fontSize];
UIFont *regularFont = [UIFont systemFontOfSize:fontSize];
UIColor *foregroundColor = [UIColor whiteColor];
// Create the attributes
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
boldFont, NSFontAttributeName,
foregroundColor, NSForegroundColorAttributeName, nil];
NSDictionary *subAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
regularFont, NSFontAttributeName, nil];
const NSRange range = NSMakeRange(rangeA, rangeB); // range of " 2012/10/14 ". Ideally this should not be hardcoded
// Create the attributed string (text + attributes)
NSMutableAttributedString *attributedText =
[[NSMutableAttributedString alloc] initWithString:labelString
attributes:attrs];
[attributedText setAttributes:subAttrs range:range];
// Set it in our UILabel and we are done!
return attributedText;
// [firstToolBarLabel setAttributedText:attributedText];
}
そして、これは私が成功せずにそれを呼び出そうとしている方法です
NSAttributedString *firstAttr = [[NSAttributedString alloc] init];
[firstAttr create.... // this dose not auto complete and I cannot see the method
理由はわかりませんが、作成したメソッドを使用できません。私はそれを正しくやっていますか?データを返す別の方法がありますか、それとも何か不足していますか
任意の助けをいただければ幸いです。