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>