200506--iOS之UITextView类

Class

UITextView

A scrollable, multiline text region.

     -- 一个可滚动的,多行的文本区域。
 

Declaration

class UITextView : UIScrollView         --继承于scrollView

Overview             --概览

UITextView supports the display of text using custom style information and also supports text editing. You typically use a text view to display multiple lines of text, such as when displaying the body of a large text document.

       --UITextView支持使用自定义样式信息显示文本,还支持文本编辑。您通常使用文本视图来显示多行文本,例如在显示大型文本文档的正文时。

This class supports multiple text styles through use of the attributedText property. (Styled text is not supported in versions of iOS earlier than iOS 6.) Setting a value for this property causes the text view to use the style information provided in the attributed string. You can still use the font, textColor, and textAlignment properties to set style attributes, but those properties apply to all of the text in the text view. It’s recommended that you use a text view—and not a UIWebView object—to display both plain and rich text in your app.

          --该类通过使用attributedText属性支持多种文本样式。(在iOS 6之前的版本中不支持样式文本。)为该属性设置一个值将导致文本视图使用该属性字符串中提供的样式信息。您仍然可以使用font, textColor, and textAlignment属性来设置样式属性,但是这些属性适用于文本视图中的所有文本。建议你使用一个text view而不是一个UIWebView对象来在你的app中显示纯文本和富文本

 

Managing the Keyboard                  --管理键盘

When the user taps in an editable text view, that text view becomes the first responder and automatically asks the system to display the associated keyboard. Because the appearance of the keyboard has the potential to obscure portions of your user interface, it is up to you to make sure that does not happen by repositioning any views that might be obscured. Some system views, like table views, help you by scrolling the first responder into view automatically. If the first responder is at the bottom of the scrolling region, however, you may still need to resize or reposition the scroll view itself to ensure the first responder is visible.

        --当用户点击一个可编辑的text view时,该文本视图将成为第一个响应器,并自动要求系统显示相关的键盘。由于键盘的外观可能会使用户界面的某些部分变得模糊,所以你需要设计子view被键盘遮住时的定位。有些系统视图,如tableView,可以帮助您自动将第一个响应器滚动到当前的view中。但是,如果第一个响应器位于滚动区域的底部,您可能仍然需要调整滚动视图的大小或位置

It is your application’s responsibility to dismiss the keyboard at the time of your choosing. You might dismiss the keyboard in response to a specific user action, such as the user tapping a particular button in your user interface. To dismiss the keyboard, send the resignFirstResponder() message to the text view that is currently the first responder. Doing so causes the text view object to end the current editing session (with the delegate object’s consent) and hide the keyboard.

          --你的app要负责在你选择文本的时候关闭键盘。您可能会针对特定的用户操作(例如用户点击用户界面中的特定按钮)而取消键盘。要取消键盘,在当前的textview上调用resignFirstResponder() 方法辞去第一响应者就可以了。这样做会导致文本视图对象结束当前编辑会话(在委托对象的同意下)并隐藏键盘。

The appearance of the keyboard itself can be customized using the properties provided by the UITextInputTraits protocol. Text view objects implement this protocol and support the properties it defines. You can use these properties to specify the type of keyboard (ASCII, Numbers, URL, Email, and others) to display. You can also configure the basic text entry behavior of the keyboard, such as whether it supports automatic capitalization and correction of the text.

         --键盘自身的外观可以使用UITextInputTraits协议提供的属性进行定制。文本视图对象遵循这个协议并支持它定义的属性。可以使用这些属性指定要显示的键盘类型(ASCII、数字、URL、电子邮件等)。您还可以配置键盘的基本文本输入行为,例如它是否支持文本的自动大小写和更正。

 

Keyboard Notifications                                 --键盘通知

When the system shows or hides the keyboard, it posts several keyboard notifications. These notifications contain information about the keyboard, including its size, which you can use for calculations that involve repositioning or resizing views. Registering for these notifications is the only way to get some types of information about the keyboard. The system delivers the following notifications for keyboard-related events:
       --当系统显示或隐藏键盘时,它会发布几个键盘通知。这些通知包含有关键盘的信息,包括键盘尺寸,您可以用来计算重新定位或调整视图大小。注册这些通知是获取有关键盘的某些类型信息的唯一方法。系统为键盘相关事件提供以下通知

  • keyboardWillShowNotification

  • keyboardDidShowNotification

  • keyboardWillHideNotification

  • keyboardDidHideNotification

For more information about these notifications, see their descriptions in UIWindow.

         --有关这些通知的更多信息,请参见它们在UIWindow中的描述。

 

State Preservation                                   --状态保存

In iOS 6 and later, if you assign a value to this view’s restorationIdentifier property, it preserves the following information:

     --在ios6及以后版本中,如果你为这个视图的restorationIdentifier属性赋值,它会保留以下信息:

  • The selected range of text, as reported by the selectedRange property.
        --文本的选定范围,由selectedRange属性报告。

  • The editing state of the text view, as reported by the isEditable property.
         --文本视图的编辑状态,由isEditable属性报告

During the next launch cycle, the view attempts to restore these properties to their saved values. If the selection range cannot be applied to the text in the restored view, no text is selected. For more information about how state preservation and restoration works, see App Programming Guide for iOS.

     --在下一个启动周期中,视图尝试将这些属性恢复到它们保存的值。如果选择范围不能应用于恢复视图中的文本,则不会选择任何文本。有关状态保存和恢复工作的更多信息,请参见iOS应用程序编程指南。

For more information about appearance and behavior configuration, see Text Views.

       --有关外观和行为配置的更多信息,请参见Text Views。

 

Topics                                              --专题

Initializing the Text View                                          --初始化textView

init(frame: CGRect, textContainer: NSTextContainer?)

Creates a new text view with the specified text container.

init?(coder: NSCoder)

 

Responding to Text View Changes                                   --响应textView的改变

var delegate: UITextViewDelegate?

The receiver’s delegate.

protocol UITextViewDelegate

The UITextViewDelegate protocol defines a set of optional methods you can use to receive editing-related messages for UITextView objects. All of the methods in this protocol are optional. You can use them in situations where you might want to adjust the text being edited (such as in the case of a spell checker program) or modify the intended insertion point.

 

Configuring the Text Attributes                             -配置文本属性

var text: String!                                                       --文本内容

The text displayed by the text view.

 

var attributedText: NSAttributedString!                                                       --文本样式

The styled text displayed by the text view.

 

var font: UIFont?                                                       --文本字体

The font of the text.  

 

var textColor: UIColor?                                                       --文本颜色

The color of the text.

 

var isEditable: Bool                                                       --是否可编辑

A Boolean value indicating whether the receiver is editable.

 

var allowsEditingTextAttributes: Bool                                                       --设置用户是否可编辑文本的样式

A Boolean value indicating whether the text view allows the user to edit style information.

 

var dataDetectorTypes: UIDataDetectorTypes                                                       --设置超链接文本的类型

The types of data converted to tappable URLs in the text view.

 

var textAlignment: NSTextAlignment                                                    --文本布局

The technique to use for aligning the text.

 

var typingAttributes: [NSAttributedString.Key : Any]                                    --设置用户正在输入的文本样式

The attributes to apply to new text being entered by the user.

 

var linkTextAttributes: [NSAttributedString.Key : Any]!                                        --设置超链接文本的样式

The attributes to apply to links.

 

var textContainerInset: UIEdgeInsets                           --文本容器在textview内容视图内的内边距。

The inset of the text container's layout area within the text view's content area.

 

Working with the Selection                        --处理选择操作    

var selectedRange: NSRange                          --当前的文本选择范围

The current selection range of the receiver.

 

func scrollRangeToVisible(NSRange)                       --滚动textView的内容到指定可见区域

Scrolls the receiver until the text in the specified range is visible.

 

var clearsOnInsertion: Bool                     --设置新输入的文本是否取代以往的文本

A Boolean value indicating whether inserting text replaces the previous contents.

 

var isSelectable: Bool                   --设置文本内容是否可选

A Boolean value indicating whether the receiver is selectable.

 

Replacing the System Input Views                 --取代系统输入视图

var inputView: UIView?               --当文本视图成为第一个响应器时显示的自定义输入视图。

The custom input view to display when the text view becomes the first responder.

 

var inputAccessoryView: UIView?               --当文本视图成为第一个响应器时显示的自定义附件视图

The custom accessory view to display when the text view becomes the first responder

 

Accessing Text Kit Objects                --访问文本工具包对象

 

var layoutManager: NSLayoutManager             --布局管理器,为使用者的文本容器布局文本。

The layout manager that lays out text for the receiver’s text container.

 

var textContainer: NSTextContainer           --文本容器对象,定义在此文本视图中要显示的文本的区域。

The text container object defining the area in which text is displayed in this text view.

 

var textStorage: NSTextStorage         --文本存储对象,用于保存此文本视图中显示的文本。

The text storage object holding the text displayed in this text view.

 

Notifications                                             --通知

class let textDidBeginEditingNotification: NSNotification.Name

Notifies observers that an editing session began in a text view. The affected view is stored in the object parameter of the notification. The userInfo dictionary is not used.

         --类,通知观察者一个编辑会话在一个文本视图中开始。受影响的视图存储在通知的对象参数中。没有使用userInfo字典。

 

class let textDidChangeNotification: NSNotification.Name

Notifies observers that the text in a text view changed. The affected view is stored in the object parameter of the notification. The userInfo dictionary is not used.

       --类,通知观察者文本视图中的文本已更改。受影响的视图存储在通知的对象参数中。没有使用userInfo字典。

 

class let textDidEndEditingNotification: NSNotification.Name

Notifies observers that the editing session ended for a text view. The affected view is stored in the object parameter of the notification. The userInfo dictionary is not used.

     --类,通知观察者,文本视图的编辑会话已结束。受影响的视图存储在通知的对象参数中。没有使用userInfo字典。

 

Constants                                --常量

struct UIDataDetectorTypes

Defines the types of information that can be detected in text-based content.

 

Instance Properties                                --实例属性

var usesStandardTextScaling: Bool

 

Relationships                                --继承关系

Inherits From

UIScrollView

Conforms To

  • CVarArg

  • Equatable

  • Hashable

  • NSTouchBarProvider

  • UIAccessibilityIdentification

  • UIContentSizeCategoryAdjusting

  • UILargeContentViewerItem

  • UIPasteConfigurationSupporting

  • UITextDraggable

  • UITextDroppable

  • UITextInput

  • UITextPasteConfigurationSupporting

  • UIUserActivityRestoring

See Also

Text Views

class UILabel

A view that displays one or more lines of informational text.

class UITextField

An object that displays an editable text area in your interface.

 

Drag and Drop Customization

Extend the standard drag and drop support for text views to include custom types of content.

你可能感兴趣的:(文本与字体相关,IOS,API阅读)