UITextview with zooming?

前端 未结 3 1441
无人及你
无人及你 2020-12-12 01:56

how can i achieve UITextview with zooming facility?any tutorial please?

相关标签:
3条回答
  • 2020-12-12 01:59

    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.

    0 讨论(0)
  • 2020-12-12 02:00

    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
    0 讨论(0)
  • 2020-12-12 02:22

    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 讨论(0)
提交回复
热议问题