IOS Development Series 4-UITextView usage Summary

Source: Internet
Author: User

IOS Development Series 4-UITextView usage Summary

// Initialize the input box and set the position and size. UITextView * textView = [[UITextView alloc] initWithFrame: CGRectMake (10, 10,300,180)]; // set the default text textView. text = @ ""; // set the text font textView. font = [UIFont fontWithName: @ "Arial" size: 16.5f]; // set the text color textView. textColor = [UIColor colorWithRed: 51/255. 0f green: 51/255. 0f blue: 51/255. 0f alpha: 1.0f]; // sets the textView background color of the text box. backgroundColor = [UIColor colorwithred: 254/255. 0f green: 254/255. 0f blue: 25 4/255. 0f alpha: 1.0f]; // sets textView for text alignment. textAlignment = NSTextAlignmentLeft; // There are several text Alignment Methods in iOS7: // enum {// NSTextAlignmentLeft = 0, left alignment, default // NSTextAlignmentCenter = 1, center Align // NSTextAlignmentRight = 2, right align // NSTextAlignmentJustified = 3, natural alignment on the last line of a paragraph // NSTextAlignmentNatural = 4, default aligment //} NSTextAlignment; // sets the Automatic Error Correction Method textView. autocorrectionType = UITextAutocorrectionTypeNo; // The following automatic error correction methods are available: // enu M {// UITextAutocorrectionTypeDefault, default // UITextAutocorrectionTypeNo, no automatic error correction // UITextAutocorrectionTypeYes, automatic error correction //} UITextAutocorrectionType; // set the automatic upper case type textView. autocapitalizationType = UITextAutocapitalizationTypeNone; // There are several automatic capitalization methods: // enum {// UITextAutocapitalizationTypeNone, which is not automatically capitalized // UITextAutocapitalizationTypeWords, the first letter is capitalized/upper, uppercase letters of a sentence // UITextAutocapit AlizationTypeAllCharacters, all letters in uppercase //} UITextAutocapitalizationType; // set the keyboard style textView. keyboardType = UIKeyboardTypeDefault; // The keyboard style includes the following types: // enum {// UIKeyboardTypeDefault; default keyboard; supports all characters // UIKeyboardTypeASCIICapable; Supports the default ASCII keyboard // keyboard, the standard phone keyboard supports + * # characters // UIKeyboardTypeURL. Only the URL keyboard with URL characters is supported. com button // UIKeyboardTypeNumberPad, digital keyboard // UIKeyboardTypePhonePad, telephone keyboard // UIKeyboa RdTypeNamePhonePad, which can be used to enter a person's name on the phone keyboard // uikeyboardtypetypeemailaddress, email keyboard // UIKeyboardTypeDecimalPad, number keyboard with number and decimal point, and UIKeyboardTypeTwitter, enter @ and # characters // UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, //} UIKeyboardType; // set the return key style textView. returnKeyType = UIReturnKeyDefault; // The return key has the following styles: // enum {// UIReturnKeyDefault, default, gray, and marked with Return // UIReturnKeyGo, blue button marked with Go // UIReturnKeyGoogle, marked Google's blue button for search // UIReturnKeyJoin, marked with Join blue button // UIReturnKeyNext, marked with Next blue button // UIReturnKeyRoute, marked with Route blue button // UIReturnKeySearch, blue button marked with Search // UIReturnKeySend, blue button marked with Send // UIReturnKeyYahoo, blue button marked with Yahoo // UIReturnKeyYahoo, blue button marked with Yahoo // UIReturnKeyEmergencyCall, emergency call button //} UIReturnKeyType; // you can specify whether textView can be dragged. scrollEnabled = YES; // sets the proxy textView. delegate = self; // custom text box placeholdertip = [U ILabel alloc] initWithFrame: CGRectMake (16, 14,320, 25)]; tip. text = @ "your opinion is the greatest motivation for us to move forward. Thank you! "; Tip. font = [UIFont fontWithName: @ "Arial" size: 16.5f]; tip. backgroundColor = [UIColor clearColor]; tip. enabled = NO; // number of words in the custom text box count = [[UILabel alloc] initWithFrame: CGRectMake (270,170, 35, 20)]; count. text = @ "240"; count. textAlignment = NSTextAlignmentRight; count. font = [UIFont fontWithName: @ "Arial" size: 15.0f]; count. backgroundColor = [UIColor clearColor]; count. enabled = NO; // display the text box and related controls [self. vie W addSubview: feedback]; [self. view addSubview: tip]; [self. view addSubview: count]; // restrict the length of input text-(BOOL) textView :( UITextView *) textView shouldChangeTextInRange :( nsange) range replacementText :( NSString *) text {if (range. location <240) {return YES;} else {return NO; }}// custom text box placeholder-(void) textViewDidChange :( UITextView *) textView {count. text = [NSString stringWithFormat: @ "% d", 240-feedback. tex T. length]; if (textView. text. length = 0) {tip. text = @ "your opinion is the greatest motivation for us to move forward. Thank you! ";}Else {tip. text = @"";}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.