UITextView displays the text in the txt file, uitextviewtxt

Source: Internet
Author: User

UITextView displays the text in the txt file, uitextviewtxt

 

:

 

 

Code:

 

-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. UITextView * textView = [[UITextView alloc] initWithFrame: CGRectMake (0,100,320,200)]; textView. backgroundColor = [UIColor redColor]; textView. textAlignment = condition; NSString * str = [NSString condition: [[NSBundle mainBundle] pathForResource: @ "brainstorming" ofType: @ "txt"] encoding: NSUTF8StringEncoding error: nil]; textView. text = str; [self. view addSubview: textView];}

 


IOS development: Get UITextView content and output txt files

NSString * textString = self. textView. text; NSLog (@ "textString is % @", textString );

How to add default text in UITextView

The placeholder attribute is inherent in UITextField and can be used to prompt information about the input box. However, UITextView does not provide this function.
Two methods are introduced for implementation:
First:
Initialize UITextView
// Define UITextView first
UITextView * textView = [[UITextView alloc] init];
TextView. font = [UIFont systemFontOfSize: 14];
TextView. frame = CGRectMake (10, 0, cell. contentView. bounds. size. width-20, side );
TextView. autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
TextView. backgroundColor = [UIColor whiteColor];
[Cell. contentView addSubview: textView];
TextView. hidden = NO;
TextView. delegate = self;
// Overwrite UILable in UITextView, and set UILable to global variable.
Uilabel. frame = CGRectMake (17, 8, cell. contentView. bounds. size. width-side + 10, 20 );
Uilabel. text = @ "Enter your approval comments ...";
Uilabel. enabled = NO; // lable must be set to unavailable
Uilabel. backgroundColor = [UIColor clearColor];
[Cell. contentView addSubview: uilabel];
Implement UITextView proxy
-(Void) textViewDidChange :( UITextView *) textView
{
Self. examineText = textView. text;
If (textView. text. length = 0 ){
Uilabel. text = @ "Enter your approval comments ...";
} Else {
Uilabel. text = @"";
}
}

Second:
UITextView implements placeholder and hides the keyboard

# Import <Foundation/Foundation. h>
@ Interface UIPlaceHolderTextView: UITextView {
NSString * placeholder;
UIColor * placeholderColor;

@ Private
UILabel * placeHolderLabel;
}

@ Property (nonatomic, retain) UILabel * placeHolderLabel;
@ Property (nonatomic, retain) NSString * placeholder;
@ Property (nonatomic, reta... the remaining full text>

Related Article

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.