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
创建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
相关文章推荐
- storyboard设置圆角按钮
- iOS--textField
- iOS:多线程NSThread的详细使用
- ios:数据持久化的几种方法浅谈
- iOS解析html
- ios:点击一个button不断切换背景图片
- iOS常用设计模式:MVC、单例、代理、观察者。
- IOS 解析XML--使用NSXML
- iOS:多线程同步加锁的简单介绍
- IOS 高德地图
- iOS 代理传值
- IOS 提交审核,Missing Push Notification Entitlement
- ios图片压缩
- iOS之 LLDB调试常用命令
- ios 本地通知
- iOS中的定时器
- iOS 使用MJRefresh刷新
- iOS中的(null) <null> nil 问题
- 关于ios9中得ALAssetsLibrary框架过时问题
- iOS开发小项目之找色块游戏