iOS开发UItextview常用属性方法

//

//  ViewController.m

//  TextViewAll

#import "ViewController.h"

@interface ViewController ()<UITextViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.view.backgroundColor = [UIColor yellowColor];

UITextView *myTextView = [[UITextView alloc]initWithFrame:CGRectMake(10, 50, [UIScreen mainScreen].bounds.size.width - 20, 200)];

//设置背景色

myTextView.backgroundColor = [UIColor brownColor];

//设置初始文本

myTextView.text = @"生活在于折腾,生活在于折腾,生活在于折腾,生活在于折腾,生活在于折腾  www.baidu.com";

//设置文字大小

myTextView.font = [UIFont systemFontOfSize:15.0];

//    myTextView.textAlignment = 1;

//    NSTextAlignmentLeft      = 0,    // 左对齐

//    NSTextAlignmentCenter    = 1,    // 居中对齐

//    NSTextAlignmentRight     = 2,    // 右对齐

//是否可以编辑

myTextView.editable = YES; // 默认YES

myTextView.selectable = YES; // 默认YES 当设置为NO时,不能选择

//替换键盘,常用语自定义键盘

UIView * view = [[UIView alloc] initWithFrame:CGRectMake(100, 50, 100, 100)];

view.backgroundColor = [UIColor redColor];

//    myTextView.inputView = view;

//在键盘上面添加一个紧贴着键盘的view,常用于 确定 OR  取消  按钮

UIView * viewSecond = [[UIView alloc] initWithFrame:CGRectMake(100, 50, 100, 50)];

viewSecond.backgroundColor = [UIColor cyanColor];

//    myTextView.inputAccessoryView = viewSecond;

//获取焦点后,自动全选文本内容

//    myTextView.clearsOnInsertion = YES; // 默认为NO

//文本与边框的距离(上,左,下右)

myTextView.textContainerInset = UIEdgeInsetsMake(20, 0, 50, 100);

myTextView.dataDetectorTypes = UIDataDetectorTypeAll;

/*UIDataDetectorTypeAll可以检测检测电话、网址和邮箱。符合条件的文本中的内容就会高亮

UIDataDetectorTypePhoneNumber                              = 1 << 0,          // Phone number detection

UIDataDetectorTypeLink                                     = 1 << 1,          // URL detection

UIDataDetectorTypeAddress NS_ENUM_AVAILABLE_IOS(4_0)       = 1 << 2,          // Street address detection

UIDataDetectorTypeCalendarEvent NS_ENUM_AVAILABLE_IOS(4_0) = 1 << 3,          // Event detection

UIDataDetectorTypeNone          = 0,               // No detection at all

*/

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"这是一个链接:www.123456.com"];

[attributedString addAttribute:NSLinkAttributeName

value:@"url1://www.baidu.com"

range:NSMakeRange(7, 14)];

NSDictionary *linkAttributes = @{NSForegroundColorAttributeName: [UIColor greenColor],

NSUnderlineColorAttributeName: [UIColor lightGrayColor],

NSUnderlineStyleAttributeName: @(NSUnderlinePatternSolid)};

myTextView.linkTextAttributes = linkAttributes;

myTextView.attributedText     = attributedString;

myTextView.delegate           = self;

myTextView.editable           = NO; // 可编辑状态不能点击链接

[self.view addSubview:myTextView];

}

// 要实现代理

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {

if ([[URL scheme] isEqualToString:@"url1"]) {

NSString * url = [URL host];

NSLog(@"%@",url);

return NO;

}

return YES;

}

// 将要开始编辑

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView

{

return YES;

}

// 将要结束编辑

- (BOOL)textViewShouldEndEditing:(UITextView *)textView

{

return YES;

}

// 开始编辑

- (void)textViewDidBeginEditing:(UITextView *)textView

{

}

// 结束编辑

- (void)textViewDidEndEditing:(UITextView *)textView

{

}

// 文本将要改变

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

{

return YES;

}

// 文本发生改变

- (void)textViewDidChange:(UITextView *)textView

{

}

// 焦点发生改变

- (void)textViewDidChangeSelection:(UITextView *)textView

{

}

// 是否允许对文本中的富文本进行操作

- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0){

return  YES;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

时间: 2024-08-28 02:34:29

iOS开发UItextview常用属性方法的相关文章

iOS开发UIPickerView常用属性方法

// //  ViewController.m //  UIPickerViewAll #import "ViewController.h" @interface ViewController () @end @implementation ViewController /* UIPickView控件常用的方法和属性: (1)  - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView; 返回Picke

IOS开发之----常用加密方法

本文转载至 http://blog.csdn.net/wildfireli/article/details/23191983 (AES.MD5.Base64) 分类: iPhone 2014-04-08 16:30 187人阅读 评论(0) 收藏 举报 目录(?)[+] 1.AES加密 NSData+AES.h文件 // // NSData-AES.h // Smile // // Created by Gary on 12-11-24. // Copyright (c) 2012年 BOX.

IOS开发中常用一下方法

1.获得屏幕的宽高 [UIScreen mainScreen].bounds.size.width [UIScreen mainScreen].bounds.size.height 2.Iphone版本判别: iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,1136), [[UIScreen mainScreen] currentMod

iOS开发中常用的参数传递方法

在iOS开发中常用的参数传递有以下几种方法: 采用代理模式 采用iOS消息机制 通过NSDefault存储(或者文件.数据库存储等) 通过AppDelegate定义全局变量(或者使用UIApplication.定义一个单例类等) 通过控制器属性传递 使用代理方式传递参数的步骤如下: 1.定义协议,协议中定义好传参时所需要的方法 2.目标视图控制器定义一个代理对象 3.源视图控制器实现协议并在初始化目标控制器时指定目标控制器的代理为其自身 4.需要传参的时候在目标窗口调用代理的协议方法

iPone应用开发 UIView 常用属性和方法

iPone应用程序开发 UIView常用属性和方法 常用属性 alpha 视图的透明度0.0f - 1.0f backgroundColor 视图的背景颜色 subviews 子视图的集合 hidden 视图是否隐藏 tag 视图的唯一标示符,是一个整形数据 superview 视图的父视图 multipleTouchEnabled 是否开启多点触控 userInteractionEnable 是否响应触摸事件 常用方法 - (void)removeFromSuperview; //从父视图中删

iOS开发之常用第三方框架(下载地址,使用方法,总结)

iOS开发之常用第三方框架(下载地址,使用方法,总结) 说句实话,自学了这么久iOS,如果说我不知道的但是又基本上都摸遍了iOS相关知识,但是每次做项目的时候,遇到难一点的地方或者没试过的东西就闷了. 比如这次,打算做一个着手做一个iOS的项目,是一个关于日计划的小软件,界面都其他的都算满意,网络就不说了,没有服务器,所以很多数据相关的功能不无法实现. 但是嘴头疼的事情就是,比如遇到一个功能的时候,其实如果说要实现的话还是可以的,但是每次在我实现之后我总会想到,这么实现更好,这么实现更简单,更加

iOS开发API常用英语名词

iOS开发API常用英语名词 0. indicating 决定 1.in order to 以便 2.rectangle bounds 矩形尺寸 3.applied 应用 4.entirety 全部 5.technique 方法 6.truncating 截短 7.wrapping  换行 8.string 字符串 9.familiar style 简体 10.The styled text 主题样式 11.Constants 常量 12.Attribute 属性 13.Consecutive

iOS开发中常用第三方库的使用和配置-GDataXML

这篇文章旨在给自己以后需要时能及时的查到,省得每次都去baidu. 1. xml解析库-GDataXML 参考文章:http://blog.csdn.net/tangren03/article/details/7868246 GDataXML下载地址: (1)GDataXML.h/m文件 http://code.google.com/p/gdata-objectivec-client/source/browse/trunk/Source/XMLSupport/ (2)DGataDefines.h

iOS开发中常用的轮子 第四篇 抽屉和侧滑效果

为避免重复造轮子,很多效果和功能都可以从github上找到.清点以前的项目,整理出了很多用过的开源代码,每天奉送一批. 学习例子的方法: 1,了解:运行一遍例子,弄清这些代码的究竟是什么: 2,使用:在之后开发工程中使用这些例子: 3,研究代码:研究例子的代码的实现,简单修改做出自己的效果. 记得要么是facebook,或是twitter第一个使用了个交互效果:而后风靡全球,是产品必用抽屉:再后来就是延生出了各种变形过的效果: 所以,产品经理要你实现抽屉和侧滑效果时,一定要确定到底是什么样抽屉和