当前位置:网站首页>Some tips for using uitextview
Some tips for using uitextview
2022-06-24 02:25:00 【Juming 12255】
1. Insert a string at the specified position :
NSMutableString *TextViewStr=[[NSMutableString alloc] initWithString:TextView.text];
[TextViewStr insertString:@"your strings" atIndex:TextView.selectedRange.location];
TextView.scrollEnabled=NO;
TextView.text=theTvStr;
theTV.scrollEnabled=YES;2. Get rows ( Including line breaks ):
CGSize size = [[self.TextView text] sizeWithFont:[self.TextView font]];
// 2. Height of extracted text
int length = size.height;
//3. Count lines
int colomNumber = TextView.contentSize.height/length;3. Detect line breaks :
- (BOOL)textView: (UITextView *)textview shouldChangeTextInRange: (NSRange)range replacementText: (NSString *)text {
if ([text isEqualToString:@"\n"]) {
NSLog(@"it is a row !!");
//...
}
return YES;
}<pre name="code" class="objc"> self.textView = [[[UITextView alloc] initWithFrame:self.view.frame] autorelease]; // Initialize size and automatically release
self.textView.textColor = [UIColor blackColor];// Set up textview The font color inside
self.textView.font = [UIFont fontWithName:@"Arial" size:18.0];// Set font name and font size
self.textView.delegate = self;// Set its delegate method
self.textView.backgroundColor = [UIColor whiteColor];// Set its background color
self.textView.text = @"Now is the time for all good developers to come to serve their country.\n\nNow is the time for all good developers to come to serve their country.";// Set what it shows
self.textView.returnKeyType = UIReturnKeyDefault;// Return the type of key
self.textView.keyboardType = UIKeyboardTypeDefault;// Keyboard type
self.textView.scrollEnabled = YES;// Can I drag
self.textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;// Adaptive height
[self.view addSubview: self.textView];// Add to the whole page notes :
The text field implements UITextInputTrait agreement , It provides 7 Attributes to define how the field handles text input :autocapitalizationType、 autocorrectionType、enablesReturnKeyAutomatically、keyboardAppearance、 keyboardType、returnKeyType、secureTextEntry. Other , When the text field is empty ,placeholder The text is grayed out , Provide a user prompt . By setting clearButtonMode You can specify whether and when to display the clear button .
If your textview You don't need to press enter in the , You can use the Enter key as a response key to exit the keyboard .
#pragma mark - UITextView Delegate Methods
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}边栏推荐
- My eight year relationship with the message queue
- Code 128 barcode details
- Where is the domain name filed? What materials are required for domain name filing?
- Must the company domain name have a trademark registration? What if the registered domain name is rejected?
- Introduction to development model + test model
- Tencent cloud won the first place in the cloud natural language understanding classification task
- Dry goods collection | the most important content collection of Tencent security in the digital ecology Conference
- Benchmarking Shopify? Similarities and differences between "two giants" of Chinese e-commerce SAAS and Weimeng
- The blue screen will be displayed at a remote location, and the error code kmode will be reported_ EXCEPTION_ NOT_ Handled, the DMP file has the keyword cdd dll
- What is the domain name trademark? What are the registration conditions for domain names and trademarks?
猜你喜欢

Advanced BOM tool intelligent packaging function

163 mailbox login portal display, enterprise mailbox computer version login portal

How to fill in and register e-mail, and open mass mailing software for free

Leetcode969: pancake sorting (medium, dynamic programming)

If there are enumerations in the entity object, the conversion of enumerations can be carried out with @jsonvalue and @enumvalue annotations

layer 3 switch

2020 language and intelligent technology competition was launched, and Baidu provided the largest Chinese data set

Review of AI hotspots this week: the Gan compression method consumes less than 1/9 of the computing power, and the open source generator turns your photos into hand drawn photos
Cloudpods golang practice

application. Yaml configuring multiple running environments
随机推荐
Mysql Find_ IN_ Set function
The cloud game is rendered by the server. How much broadband does the server need
Mainstay of network detection - nping User Guide
[tcapulusdb knowledge base] manually view the online operation of tcapulusdb
Is a trademark domain name useful? How long does it take to register a domain name?
[new features] Tencent cloud lightweight ECS will soon support attaching data disks!!!
Build your own cloud game server. What if the cloud game server is attacked
Xmlmap port practice - X12 to CSV
Efficient Internet access and systematic learning
Cloud recommendation Vol.1: quick start to remote control under f-stack, go modules and 5g!
Start tcapulusdb process
Live broadcast of the double 11 King bombing! Must buy good things introduction, come on~
How to handle the abnormal state of easycvr national standard cascading superior display?
Leetcode838: push domino (medium)
The blue screen will be displayed at a remote location, and the error code kmode will be reported_ EXCEPTION_ NOT_ Handled, the DMP file has the keyword cdd dll
How do I fix the iPhone green screen problem? Try these solutions
application. Yaml configuring multiple running environments
What is the difference between trademark registration and company domain name? What is the difference between the two?
Data backup is required for manual upgrade of WordPress website program
What is a region name? Can a territory name be used for trademark registration?