Formatting and Bullets in a TextBox in iOS5

独自空忆成欢 提交于 2020-02-05 04:37:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!