Objective c 有没有办法完成一半的换行?

Objective c 有没有办法完成一半的换行?,objective-c,unicode,nsstring,ascii,Objective C,Unicode,Nsstring,Ascii,我想知道,是否有一种方法可以在目标C中的NSString中执行新行字符(\n)的一半,即只跳过大约一半的空间?或者在NSString?中实现这一点,就像Wain所说的,在NSAttributed字符串上设置NSParagraphStyle可能就是您想要的。UILabel在iOS 6中支持NSAttributedString,但在此之前,您必须使用第三方组件。非常好并且有很好的文档记录 NSMutableAttributedString* attrStr = [NSMutableAttribute

我想知道,是否有一种方法可以在目标C中的
NSString
中执行新行字符(
\n
)的一半,即只跳过大约一半的空间?或者在
NSString

中实现这一点,就像Wain所说的,在NSAttributed字符串上设置NSParagraphStyle可能就是您想要的。UILabel在iOS 6中支持NSAttributedString,但在此之前,您必须使用第三方组件。非常好并且有很好的文档记录

NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:@"Hello World!"];
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
[style setLineSpacing:24]; //Just a random value, you'll have to play with it till you are hhappy
[attrStr addAttribute:NSParagraphStyleAttributeName
                  value:style
                  range:NSMakeRange(0, [myString length])];
label.attributedText = attrStr;
如果您最终使用的是
TTTAttributedLabel
,那么您将使用
label.text=attrStr
或其中一个助手方法(取自
TTTAttributedLabel
文档:

[label setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
  NSRange boldRange = [[mutableAttributedString string] rangeOfString:@"ipsum dolar" options:NSCaseInsensitiveSearch];
  NSRange strikeRange = [[mutableAttributedString string] rangeOfString:@"sit amet" options:NSCaseInsensitiveSearch];

  // Core Text APIs use C functions without a direct bridge to UIFont. See Apple's "Core Text Programming Guide" to learn how to configure string attributes.
  UIFont *boldSystemFont = [UIFont boldSystemFontOfSize:14];
  CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL);
  if (font) {
    [mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(id)font range:boldRange];
    [mutableAttributedString addAttribute:kTTTStrikeOutAttributeName value:[NSNumber numberWithBool:YES] range:strikeRange];
    CFRelease(font);
  }

  return mutableAttributedString;
}];

另外,
TTATAttributedLabel
有一个
lineHeightMultiple
(介于0.0和1.0之间)属性,您可以通过该属性来获得所需的效果。这样,您仍然可以使用
NSString
,而不会弄乱有时丑陋的
NSAttributedString
,这是什么意思“做半个换行"?你想实现什么?@aleroot-我的意思是新行通常会产生的一半空间。我有一些要点,我想在项目符号和引入项目符号的文本之间留一点空间。常规新行的空间太大,大约有一半是对的。你看过
NSParagraphStyle