您的位置:首页 > 移动开发 > IOS开发

iOS--textview

2015-10-06 21:01 363 查看
1.创建并初始化

创建UITextView的文件,并在.h文件中写入如下代码:

#import <UIKit/UIKit.h>

@interface TextViewController : UIViewController <UITextViewDelegate>

{

UITextView *textView;

}

@property (nonatomic, strong) UITextView *textView;

@end

在.m文件中初始化这个textview,写入代码如下:

self.textView = [[[UITextView alloc] initWithFrame:self.view.frame]autorelease]; //初始化大小并自动释放

self.textView.textColor = [UIColor blackColor];//设置textview里面的字体颜色

self.textView.font = [UIFont fontWithName:@"Arial" size:18.0];//设置字体名字和字体大小

self.textView.delegate = self;//设置它的委托方法

self.textView.backgroundColor = [UIColor whiteColor];//设置它的背景颜色

self.textView.text = @"Now is the time for all good developers tocome to serve their country.\n\nNow is the time for all good developers to cometo serve their country.";//设置它显示的内容

self.textView.returnKeyType = UIReturnKeyDefault;//返回键的类型

self.textView.keyboardType = UIKeyboardTypeDefault;//键盘类型

self.textView.scrollEnabled = YES;//是否可以拖动

self.textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度

[self.view addSubview: self.textView];//加入到整个页面中

[self.view addSubview: self.textView];//加入到整个页面中

textView.alpha = 1;

textView.backgroundColor = [UIColor blackColor];

textView.editable =NO;

textView.textAlignment = UITextAlignmentCenter;

textView.textColor = [UIColor whiteColor];

textView.font = [UIFont fontWithName:@"Marker Felt" size:30];

textView.text = @"从前sfsfdsfdsaaaaaaaaaaaaaaaaaaaaayufguighjgfuygggiugjkvgftvuytdcvtboybnbyubuvtyftyuruygyguyfytvtbiyiuuybtvc6r78vt7tb98yyfv67r6bt78v6r7cdeseerdftuyfgiyfyucghcchcghcghccgcghcghgyuuigyy89tr67r67xfcghhvjguugiuifuytftfyfuguiutfuftfyugiguiuifyufufyuyfgui";

textView.contentOffset = CGPointMake(0, -100);

textView.indicatorStyle = UIScrollViewIndicatorStyleWhite;

textView.clipsToBounds = YES;

textView.scrollEnabled = YES;

[textView setCanCancelContentTouches:NO];

textView.showsHorizontalScrollIndicator = NO;

textView.showsVerticalScrollIndicator = NO;
http://blog.csdn.net/qq_31810357/article/details/49254969
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: