views:

32

answers:

2

Is there any way to make a bullet point list in iphone?

If you copy and paste a bullet point list into a UITextView in IB then it shows up. Is there anyway to do this programatically?

Thank you

Tom

+1  A: 

As far as I know the only way to archive this (and almost any other formatted rich-text) on the iPhone is to use a UIWebView and insert HTML-Code like this:

<ul>
     <li>Bullet</li>
</ul>

In response to your comment, UIWebViews can be "beautified" by the following peace of code:

for(UIView* v in webView.subviews){
    if([v isKindOfClass:[UIScrollView class] ]){

        //disable bouncing
        UIScrollView* sv = (UIScrollView*) v;
        sv.alwaysBounceVertical = NO;
        sv.alwaysBounceHorizontal = NO;

        //disable scroll-shadows
        for (UIView *subView in [sv subviews])
            if ([[[subView class] description] isEqualToString:@"UIImageView"])
                subView.hidden = YES;
    }
}

I haven't submitted this yet but I guess it should be "AppStore safe".

Phlibbo
i hate UIWebViews - they give me that ugly "bounce" gutter at the top and bottom. :( but thanks
Thomas Clayson
I share your feelings about WebViews, but they can be improved. Have a look at my edited post!
Phlibbo
Iterating through the subviews of a `UIWebView` is considered a private API. Don't assume it will be accepted.
rpetrich
That's good to know, thank you!
Phlibbo
+1  A: 

The "bullet" character is at Unicode code point U+2022. You can use it in a string with @"\u2022" or [NSString stringWithFormat:@"%C", 0x2022].

The "line feed" character is at Unicode code point U+000A, and is used as UIKit's newline character. You can use it in a string with @"\n".

For example, if you had an array of strings, you could make a bulleted list with something like this:

NSArray * items = ...;
NSMutableString * bulletList = [NSMutableString stringWithCapacity:items.count*30];
for (NSString * s in items)
{
  [bulletList appendFormat:@"\u2022 %@\n", s];
}
textView.text = bulletList;

It won't indent lines like a "proper" word processor. "Bad things" will happen if your list items include newline characters (but what did you expect?).

(Apple doesn't guarantee that "\uXXXX" escapes work in NSString literals, but in practice they do if you use Apple's compiler.)

tc.
this is brilliant (provided it works) :) Thank you.
Thomas Clayson