Simple NSTextList question

后端 未结 1 1397
庸人自扰
庸人自扰 2021-02-11 00:57

I am trying to use NSTextList to display a numeric list in a multi-line NSTextField but it is not working as intended.

The sample code used is:

1条回答
  •  Happy的楠姐
    2021-02-11 01:29

    Everything you are doing looks fine and ornately to me:) There is a problem with your input string Try this,

    NSTextList *list1 = [[NSTextList alloc] initWithMarkerFormat:@"{decimal}" options:0]; // {Decimal} passed as marker format
    NSMutableParagraphStyle *paragraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    [list1 setStartingItemNumber:1];
    [paragraph setTextLists:[NSArray arrayWithObject:list1]];
    
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:paragraph, NSParagraphStyleAttributeName, nil];
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"\t%@ Suhas \n \t%@ Devarshi \n \t%@ Rohith\n", [list1 markerForItemNumber:1],[list1 markerForItemNumber:2],[list1 markerForItemNumber:3]] attributes:attributes] ;
     [self.text setStringValue:attrString];//self.text is a NSTextField instance. kindly ignore the compiler warning:)
    

    0 讨论(0)
提交回复
热议问题