Multi-line read-write text iOS9 text view for IOS 9 app development Tutorials

Source: Internet
Author: User

Multi-line read-write text iOS9 text view for IOS 9 app development Tutorialsmulti-line read and write text--ios9text View

text view is also an input control, unlike a text box, where the text view allows the user to enter multiple lines, 2.23 is shown. In this figure, the string "Say something." This area is implemented using Text view, where users can write large amounts of text content. The General text box view is implemented using uitextview .

Figure 2.23 Write Log

The example 2-9 The following will be implemented using the text view QQ write about and publish the function. The following steps are described:

( 1 ) Create a single View application template type project, named uitextview

( 2 ) Open Main.storyboard document, design the main view, effect 2.24 is shown.

The views you need to add and the settings for them, such as table 2-6 is shown.

Table 2-6 settings for a View object

Figure 2.24 the effect of the main view

( 3 ) Open Viewcontroller.swift file, write code, this code implements the function is to write to say and publish the function. The code is as follows:

  • Import UIKit

  • Class Viewcontroller:uiviewcontroller,uitextviewdelegate {

  • Let Wtv=uitextview (Frame:cgrectmake (0, 375, 232))

  • Let Rtv=uitextview (Frame:cgrectmake (0, 372, 375, 232))

  • Let Label=uilabel (Frame:cgrectmake (3, 105, 123, 21))

  • Override Func Viewdidload () {

  • Super.viewdidload ()

  • Additional setup after loading the view, typically from a nib.

  • & nbsp       Self.view.addSubview (WTV)                              // add text view

  • & nbsp       label.text= " say something ..."                                   // Set the text content of the label

  • Label.enabled=false// Disabling Labels

  • Label.backgroundcolor=uicolor.clearcolor ()

  • wtv.delegate=self// to set a delegate for a text view

  • Self.view.addSubview (label)

  • Self.view.addSubview (RTV)

  • Rtv.backgroundcolor=uicolor.clearcolor ()

  • & nbsp       rtv.editable=false                                                         // disable text view

  • rtv.hidden=true// Hide Text View

  • }

  • // Listen for text change messages

  • Func Textviewdidchange (Textview:uitextview) {

  •     // determines whether the contents of the text view are empty

  • if (wtv.text== "") {

  • label.text= " say something. ..."

  • }else{

  • Label.hidden=true

  • }

  • }

  • // Hide Keyboard

  • @IBAction func Cancel (sender:anyobject) {

  • Wtv.resignfirstresponder ()

  • }

  • // publish and say, hide the keyboard

  • @IBAction func Issue (Sender:anyobject) {

  • Rtv.hidden=false

  • Rtv.text=wtv.text// set the text content of a text view

  • Wtv.resignfirstresponder ()

  • }

  • ......

  • }

After you run the program, you see 2.25 The effect shown. When the developer taps the text view, the keyboard automatically pops up,as shown in2.26 .

figure Span style= "line-height:1.5" >2.25   run effect Span style= "line-height:1.5" >                                   2.26    run effect

when the developer enters content in the text view, the string "Say something ... .. "It will automatically disappear, 2.27 is shown. When you tap the Publish button, the content that you write in the text view appears in another text view, and the keyboard disappears,as shown in2.28 .

figure Span style= "line-height:1.5" >2.27   run effect Span style= "line-height:1.5" >                                    2.28    run effect

This article is selected from: IOS 9 Application Development Basic Tutorial University PA Internal information, reproduced please indicate the source, respect the technology respect the IT person!


Multi-line read-write text iOS9 text view for IOS 9 app development Tutorials

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.