开发者

UITextview with zooming?

how can i achieve UITextview wi开发者_如何学运维th zooming facility?any tutorial please?


You can make simple UIWebView and it will be like UITextView, but with zooming. This way has a lot of advantages. For example bold text, or italic. You will be able to use different fonts in one text.

Step by step guide:

  • create UIWebView
  • generate html string. For example: <html><head></head><body>My text</body></html>
  • load string in UIWebView


If I'm understanding your question correctly, you want a UITextView, and you want to allow the user to use two fingers to zoom in? If that's the case, when you add the UITextView in IB, at the bottom of the settings for the UITextView there is a check box for "Multiple Touch" just check that box and it will allow the user to zoom in. Hope I understood your question correctly.


If you not need user to edit text and just need to show some text with ability to change font attributes (i.e. size, weight) - use attributed string of text view. Then allow editing attributes and just call methods from UIResponderStandardEditActions protocol, like increaseSize: or decreaseSize: on UITextView. Before it you should set a range of text which must be affected:

self.textView.editable = NO;
self.textView.selectable = NO;
self.textView.allowsEditingTextAttributes = YES;
self.textView.attributedText = [[NSAttributedString alloc] initWithString:@"Lorem ipsum dolor sit er elit lamet..."];

Before calling increase/decrease method select all text:

//First select needed range 
[self.textView setSelectedRange:NSMakeRange(0, self.textView.attributedText.length)];

//Then call increazing method
[self.textView increazeSize:nil];

Also you can call other methods of that nice protocol, which UITextView kindly implement:

[self.textView decreaseSize:sender];
[self.textView toggleBoldface:nil];
[self.textView toggleItalics:nil];
[self.textView toggleUnderline:nil];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜