NSAttributedStringの段落の行数を制限する方法はありますか? NSAttributedString
に
2 つの文字列を追加します。それらを最大 3 行にしたいのですが、最初の文字列は 1 ~ 2 行になり、必要に応じて切り捨てられます。2番目の文字列は常に最後の行にある必要があります
。
this is my first string
if its too long i't will get trun...
But this is my second string
私がしたことは:
// First string
NSAttributedString *first = [[NSAttributedString alloc] initWithString:@"this is my first string if its too long i't will get trunticated"
attributes:@{NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:17.0]];
[str appendAttributedString:first];
// New line
[str appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
// Add photo count
NSAttributedString *second = [[NSAttributedString alloc] initWithString:@"But this is my second string"
attributes:@{NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:14.0]}];
[str appendAttributedString:second];
しかし、結果は次のとおりです。
this is my first string
if its too long i't will get
trunticated
最初の文字列は最初の 3 行を取り、2 番目の文字列をラベルから押し出します。
最初の文字列段落を 2 行に制限するにはどうすればよいですか?