Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8182879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:59:26+00:00 2026-06-07T00:59:26+00:00

I have a UITextView and I want have two buttons. When the user taps

  • 0

I have a UITextView and I want have two buttons. When the user taps the back button I want the cursor to move back 1 character. When they tap to forward button the cursor should move forward 1 character. How could I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:59:28+00:00Added an answer on June 7, 2026 at 12:59 am

    I wrote it out for you, referencing the answer linked below. You can drop the code I wrote into a basic project and try it out.

    The solution idea:

    You can programmatically select a block of text by specifying the range of text to select (see reference). What’s a range, you ask? It’s basically a starting position and a length. Since you only care about the cursor position, you can ignore the length (i.e. keep it at zero) and adjust the starting position of the “selection” by +1 or -1.

    Reference:

    Can I select a specific block of text in a UITextField?

    Code Explanation:

    In the code below, there are two buttons (Forward and Back) and a target method for each of them that changes the cursor position in the UITextView. Note that tv is the class variable/property for your UITextView (and needs to be declared as such).

    The Code:

    - (void)viewDidLoad {
        [super viewDidLoad];
        UIButton *forward = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        forward.frame = CGRectMake(20, 20, 100, 50);
        [forward setTitle:@"Forward" forState:UIControlStateNormal];
        [forward addTarget:self action:@selector(moveForward:) forControlEvents:UIControlEventTouchUpInside];
    
        UIButton *back = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        back.frame = CGRectMake(130, 20, 100, 50);
        [back setTitle:@"Back" forState:UIControlStateNormal];    
        [back addTarget:self action:@selector(moveBack:) forControlEvents:UIControlEventTouchUpInside];
    
        tv = [[UITextView alloc] initWithFrame:CGRectMake(20, 120, 280, 100)];
        [self.view addSubview:forward];
        [self.view addSubview:back];
        [self.view addSubview:tv];    
    }
    
    
    -(void)moveForward:(id)sender {
        UITextRange *selectedRange = [tv selectedTextRange];
        // Calculate the new position, - for left and + for right
    
        if (tv.selectedRange.location < tv.text.length) {
            UITextPosition *newPosition = [tv positionFromPosition:selectedRange.start offset:1];
    
            UITextRange *newRange = [tv textRangeFromPosition:newPosition toPosition:newPosition];
    
            // Set new range
            [tv setSelectedTextRange:newRange];
        }
    }
    
    -(void)moveBack:(id)sender {
        UITextRange *selectedRange = [tv selectedTextRange];
        // Calculate the new position, - for left and + for right
    
        if (tv.selectedRange.location > 0) {
            UITextPosition *newPosition = [tv positionFromPosition:selectedRange.start offset:-1];
    
            UITextRange *newRange = [tv textRangeFromPosition:newPosition toPosition:newPosition];
    
            // Set new range
            [tv setSelectedTextRange:newRange];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITextView(not editable). When user tries to select text I want to
I have two UITextViews that I want to be displayed when the user sends
I have a UITextView. When the user hits the Send key I want to
Setup: I have a UITextView inside a UITableViewCell 's contentView . I want it
i have a problem, i want set text of a UILabel or UItextView or
I have a UITextView that has a lot of content. I have a button
I have an UITextView and I don't want check editable option, how can call
I want to have to occasionally insert text into the UITextView text object. For
I have a view with two UITextView elements in it, each of which is
I have created a UITextView programatically and want to enable scrolling for that UITextView.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.