问题
Does anyone know how to insert bullets and do some formatting in a textbox, maybe in a webview (as shown in the print screen below) in iOS 5, XCode 4.3?
回答1:
For the UITextView
manually add dots and newlines, for example:
NSArray *items = [NSArray arrayWithObjects:@"Stack",@"Overflow",nil];
NSMutableString *formattedString = [[NSMutableString alloc] init ];
for (NSString *item in items) [formattedString appendFormat:@"\u2022 %@\n", item];
theTextViewName.text = formattedString;
For the UIWebView
create an unordered HTML
list, for example:
NSArray *items = [NSArray arrayWithObjects:@"Stack",@"Overflow",nil];
NSMutableString *theSource = [[NSMutableString alloc] init ];
[theSource appendFormat:@"<ul>"];
for (NSString *item in items) [theSource appendFormat:@"<li>%@</li>", item];
[theSource appendFormat:@"</ul>"];
[theWebView loadHTMLString:theSource baseURL:nil];
Both result into the following list:
- Stack
- Overflow
来源:https://stackoverflow.com/questions/11365941/formatting-and-bullets-in-a-textbox-in-ios5