iOS Development Uitextview Common attribute methods
Source: Internet
Author: User
<span id="Label3"></p><p><p>//</p></p><p><p>Viewcontroller.m</p></p><p><p>Textviewall</p></p><p><p>#import "ViewController.h"</p></p><p><p></p></p><p><p>@interface Viewcontroller () <UITextViewDelegate></p></p><p><p></p></p><p><p>@end</p></p><p><p></p></p><p><p>@implementation Viewcontroller</p></p><p><p></p></p><p><p>-(void) Viewdidload {</p></p><p><p>[super viewdidload];</p></p><p><p>Self.view.backgroundColor = [uicolor yellowcolor];</p></p><p><p></p></p><p><p>Uitextview *mytextview = [[uitextview alloc]initwithframe:cgrectmake (uiscreen mainscreen].bounds.size.width- 20, 200)];</p></p><p><p>Set Background color</p></p><p><p>Mytextview.backgroundcolor = [uicolor browncolor];</p></p><p><p>Set initial text</p></p><p><p>Mytextview.text = @ "life is tossing, life is tossing, life is tossing, life is tossing, life is tossing and www.baidu.com";</p></p><p><p>Set Text Size</p></p><p><p>Mytextview.font = [uifont systemfontofsize:15.0];</p></p><p><p>Mytextview.textalignment = 1;</p></p><p><p>Nstextalignmentleft = 0,//left Justified</p></p><p><p>Nstextalignmentcenter = 1,//center Alignment</p></p><p><p>Nstextalignmentright = 2,//right Justified</p></p><p><p></p></p><p><p>Whether you can edit</p></p><p><p>Mytextview.editable = YES; Default Yes</p></p><p><p></p></p><p><p>Mytextview.selectable = YES; Default Yes when set to no, you cannot select</p></p><p><p></p></p><p><p>Replace keyboard, Common Language custom keyboard</p></p><p><p>UIView * view = [[UIView alloc] initwithframe:cgrectmake (100, 50, 100, 100)];</p></p><p><p>View.backgroundcolor = [uicolor redcolor];</p></p><p><p>Mytextview.inputview = view;</p></p><p><p></p></p><p><p>Add a view on the keyboard that is attached to the keyboard, often used to determine the OR Cancel button</p></p><p><p>UIView * Viewsecond = [[UIView alloc] initwithframe:cgrectmake (100, 50, 100, 50)];</p></p><p><p>Viewsecond.backgroundcolor = [uicolor cyancolor];</p></p><p><p>Mytextview.inputaccessoryview = viewsecond;</p></p><p><p>Automatically select all text content after you get the focus</p></p><p><p>Mytextview.clearsoninsertion = YES; Default is No</p></p><p><p>The distance between the text and the border (top, left, bottom Right)</p></p><p><p>Mytextview.textcontainerinset = Uiedgeinsetsmake (20, 0, 50, 100);</p></p><p><p></p></p><p><p>Mytextview.datadetectortypes = uidatadetectortypeall;</p></p><p><p>/*uidatadetectortypeall can detect phone calls, urls, and Mailboxes. The content in the eligible text will be highlighted</p></p><p><p>Uidatadetectortypephonenumber = 1 << 0,//Phone number detection</p></p><p><p>Uidatadetectortypelink = 1 << 1,//URL detection</p></p><p><p>uidatadetectortypeaddress Ns_enum_available_ios (4_0) = 1 << 2,//Street address detection</p></p><p><p>Uidatadetectortypecalendarevent Ns_enum_available_ios (4_0) = 1 << 3,//Event detection</p></p><p><p></p></p><p><p>Uidatadetectortypenone = 0,//No detection at all</p></p><p><p>*/</p></p><p><p>nsmutableattributedstring *attributedstring = [[nsmutableattributedstring alloc] initwithstring:@ " This is a link: www.123456.com "];</p></p><p><p>[attributedstring Addattribute:nslinkattributename</p></p><p><p>value:@ "url1://www.baidu.com"</p></p><p><p>Range:nsmakerange (7, 14)];</p></p><p><p>Nsdictionary *linkattributes = @{nsforegroundcolorattributename: [uicolor greencolor],</p></p><p><p>Nsunderlinecolorattributename: [uicolor lightgraycolor],</p></p><p><p>Nsunderlinestyleattributename: @ (nsunderlinepatternsolid)};</p></p><p><p>Mytextview.linktextattributes = linkattributes;</p></p><p><p>Mytextview.attributedtext = attributedstring;</p></p><p><p>Mytextview.delegate = self;</p></p><p><p>Mytextview.editable = NO; Editable status cannot be clicked on the link</p></p><p><p>[self.view addsubview:mytextview];</p></p><p><p></p></p><p><p>}</p></p><p><p>To implement a proxy</p></p><p><p>-(BOOL) textView: (uitextview *) textView shouldinteractwithurl: (nsurl *) URL inrange: (nsrange) characterrange {</p></p><p><p>If ([[URL scheme] isequaltostring:@ "url1"]) {</p></p><p><p>NSString * url = [url host];</p></p><p><p>NSLog (@ "%@", url);</p></p><p><p>Return NO;</p></p><p><p>}</p></p><p><p>Return YES;</p></p><p><p>}</p></p><p><p>Going to start editing</p></p><p><p>-(BOOL) textviewshouldbeginediting: (uitextview *) TextView</p></p><p><p>{</p></p><p><p>Return YES;</p></p><p><p>}</p></p><p><p>Going to end the edit</p></p><p><p>-(BOOL) textviewshouldendediting: (uitextview *) TextView</p></p><p><p>{</p></p><p><p>Return YES;</p></p><p><p>}</p></p><p><p></p></p><p><p>Start editing</p></p><p><p>-(void) textviewdidbeginediting: (uitextview *) TextView</p></p><p><p>{</p></p><p><p></p></p><p><p>}</p></p><p><p>End Edit</p></p><p><p>-(void) textviewdidendediting: (uitextview *) TextView</p></p><p><p>{</p></p><p><p></p></p><p><p>}</p></p><p><p></p></p><p><p>The text is going to change</p></p><p><p>-(BOOL) textView: (uitextview *) textView shouldchangetextinrange: (nsrange) range replacementtext: (nsstring *) text</p></p><p><p>{</p></p><p><p>Return YES;</p></p><p><p>}</p></p><p><p>The text has changed</p></p><p><p>-(void) textviewdidchange: (uitextview *) TextView</p></p><p><p>{</p></p><p><p></p></p><p><p>}</p></p><p><p>The focus has Changed.</p></p><p><p>-(void) textviewdidchangeselection: (uitextview *) TextView</p></p><p><p>{</p></p><p><p></p></p><p><p>}</p></p><p><p>Whether to allow manipulation of rich text in text</p></p><p><p>-(BOOL) textView: (uitextview *) textView shouldinteractwithtextattachment: (nstextattachment *) textattachment inrange :(nsrange) CharacterRange Ns_available_ios (7_0) {</p></p><p><p>Return YES;</p></p><p><p>}</p></p><p><p></p></p><p><p>-(void) didreceivememorywarning {</p></p><p><p>[super didreceivememorywarning];</p></p><p><p>Dispose of any resources the can be Recreated.</p></p><p><p>}</p></p><p><p></p></p><p><p></p></p><p><p>@end</p></p><p><p></p></p><p><p>iOS Development Uitextview Common attribute methods</p></p></span>
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