9.21. The use of IOS text views

发布时间 :2025-10-25 12:23:55 UTC      

The text view is used to display text with multiple lines of scrolling.

9.21.1. Important attribute

  • DataDetectorTypes

  • Delegate

  • Editable

  • InputAccessoryView

  • InputView

  • Text

  • TextAlignment

  • TextColor

An important delegation method

-(void)textViewDidBeginEditing:(UITextView *)textView
-(void)textViewDidEndEditing:(UITextView *)textView
-(void)textViewDidChange:(UITextView *)textView
-(BOOL)textViewShouldEndEditing:(UITextView *)textView

Add a custom method addTextView

-(void)addTextView{
    myTextView = [[UITextView alloc]initWithFrame:
    CGRectMake(10, 50, 300, 200)];
    [myTextView setText:@"Lorem ipsum dolor sit er elit lamet, consectetaur
    cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et
    dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
    ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
    dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
    nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
    culpa qui officia deserunt mollit anim id est laborum. Nam liber te
    conscient to factor tum poen legum odioque civiuda.
    Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing
    pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aiqua.
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
    aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
    in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
    Excepteur sint occaecat cupidatat non proident, sunt in culpa
    qui officia deserunt mollit anim id est laborum. Nam liber te conscient
    to factor tum poen legum odioque civiuda."];
    myTextView.delegate = self;
    [self.view addSubview:myTextView];

}

Perform a textView delegate in ViewController.m

#pragma mark - Text View delegates

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:
 (NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
    }
    return YES;
}
-(void)textViewDidBeginEditing:(UITextView *)textView{
    NSLog(@"Did begin editing");
}
-(void)textViewDidChange:(UITextView *)textView{
    NSLog(@"Did Change");

}
-(void)textViewDidEndEditing:(UITextView *)textView{
    NSLog(@"Did End editing");

}
-(BOOL)textViewShouldEndEditing:(UITextView *)textView{
    [textView resignFirstResponder];
    return YES;
}

Modify the viewDidLoad method in ViewController.m, as shown below

(void)viewDidLoad
{
   [super viewDidLoad];
   [self addTextView];
}

9.21.2. Result output

Now when we run the application, we will see the following output

textViewOutput

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.