主要内容

按钮属性

Control button appearance and behavior

按钮是UI组件,当用户按下并释放它们时响应。通过更改属性值,您可以修改按钮的外观和行为。使用点表示法来引用特定对象和属性。

fig = uifigure; b = uibutton(fig); b.Text = 'Plot';

Button

展开全部

按钮标签, specified as a character vector, cell array of character vectors, string scalar, string array, or 1-D categorical array. Specify a character vector or string scalar to label the button with a single line of text. Use a cell array or string array to label the button with multiple lines of text. Each element in the array represents a separate line of text. If you specify this property as a categorical array, MATLAB®使用数组中的值,而不是完整的类别。

单词包装以适应组件宽度,指定为'离开'或者'on',或作为数字或逻辑0(false) or1(真的). A value of'离开'相当于false, 和'on'相当于真的。Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of typematlab.lang.OnoffSwitchState.

使用此属性以防止在组件的宽度小于要显示的文本时水平剪裁。

  • '离开'— Text does not wrap.

  • 'on'— Breaks text into new lines so that each line fits within the width of the component and avoids breaking words when possible.

设置WordWrap.property to'on'does not prevent text from getting clipped vertically when the height of the component is too small to display all the lines of text.

图标源或文件,指定为字符向量,字符串标量或者m-经过-n-3-3 TrueColor图像数组。If you specify a file name, it can be an image file name on the MATLAB path or a full path to an image file. If you plan to share an app with others, put the image file on the MATLAB path to facilitate app packaging.

Supported image formats include JPEG, PNG, GIF, SVG, orm-经过-n-3-3 TrueColor图像数组。有关TrueColor图像阵列的更多信息,请参阅Image Types

  • 如果是button text takes up all the space specified by thePosition属性值,然后matlab不显示图标。

  • 如果一些房间是可用的图标,然后MATLAB scales down the image to fit, if necessary.

例子:'icon.png'指定MATLAB路径上的图标文件。

例子:'c:\ documents \ icon.png'指定图像文件的完整路径。

Font and Color

展开全部

字体名称, specified as a system supported font name. The default font depends on the specific operating system and locale.

如果指定的字体不可用,则Matlab使用应用程序正在运行的系统上可用的字体之间的最佳匹配。

例子:'arial'

Font size, specified as a positive number. The units of measurement are pixels. The default font size depends on the specific operating system and locale.

例子:14.

字体重量,指定为其中一个值:

  • 'normal'— Default weight as defined by the particular font

  • '大胆的'- 比较厚的字符概述'normal'

Not all fonts have a bold font weight. Therefore, specifying a bold font weight can result in the normal font weight.

Font angle, specified as'normal'或者'italic'。将此属性设置为斜体selects a slanted version of the font, if it is available on the app user’s system.

字体颜色,指定为RGB三联网,十六进制颜色代码或表中列出的选项之一。

RGB三元组和十六进制颜色代码对于指定自定义颜色很有用。

  • An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range[0,1];例如,[0.4 0.6 0.7]

  • 十六进制颜色代码是字符向量或以哈希符号开头的字符串标量(#)接着是三个或六个十六进制数字,可以从0F。这些值不区分大小写。因此,颜色代码'#ff8800','#ff8800','#f80', 和'#f80'are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color Name 简称 RGB Triplet Hexadecimal Color Code Appearance
'red' 'r' [1 0 0] '#FF0000'

'green' 'G' [0 1 0] '#00FF00'

'蓝色的' 'B' [0 0 1] '#0000FF'

'青色' 'C' [0 1 1] '#00ffff'

'品红' 'M' [1 0 1] '#ff00ff'

'黄色的' 'y' [1 1 0] '#FFFF00'

'黑色的' 'K' [0 0 0] '#000000'

'white' 'w' [1 1 1] '#FFFFFF'

以下是RGB三元组和十六进制颜色代码,用于默认颜色MATLAB在许多类型的图中使用。

RGB Triplet Hexadecimal Color Code Appearance
[0 0.4470 0.7410] '#0072bd'

[0.8500 0.3250 0.0980] '#D95319'

[0.9290 0.6940 0.1250] '#EDB120'

[0.4940 0.1840 0.5560] '#7E2F8E'

[0.4660 0.6740 0.1880] “# 77 ac30”

[0.3010 0.7450 0.9330] '#4dbeee'

[0.6350 0.0780 0.1840] '#A2142F'

背景颜色, specified as an RGB triplet, a hexadecimal color code, or one of the color options listed in the table.

RGB三元组和十六进制颜色代码对于指定自定义颜色很有用。

  • An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range[0,1];例如,[0.4 0.6 0.7]

  • 十六进制颜色代码是字符向量或以哈希符号开头的字符串标量(#)接着是三个或六个十六进制数字,可以从0F。这些值不区分大小写。因此,颜色代码'#ff8800','#ff8800','#f80', 和'#f80'are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color Name 简称 RGB Triplet Hexadecimal Color Code Appearance
'red' 'r' [1 0 0] '#FF0000'

'green' 'G' [0 1 0] '#00FF00'

'蓝色的' 'B' [0 0 1] '#0000FF'

'青色' 'C' [0 1 1] '#00ffff'

'品红' 'M' [1 0 1] '#ff00ff'

'黄色的' 'y' [1 1 0] '#FFFF00'

'黑色的' 'K' [0 0 0] '#000000'

'white' 'w' [1 1 1] '#FFFFFF'

以下是RGB三元组和十六进制颜色代码,用于默认颜色MATLAB在许多类型的图中使用。

RGB Triplet Hexadecimal Color Code Appearance
[0 0.4470 0.7410] '#0072bd'

[0.8500 0.3250 0.0980] '#D95319'

[0.9290 0.6940 0.1250] '#EDB120'

[0.4940 0.1840 0.5560] '#7E2F8E'

[0.4660 0.6740 0.1880] “# 77 ac30”

[0.3010 0.7450 0.9330] '#4dbeee'

[0.6350 0.0780 0.1840] '#A2142F'

互动

展开全部

可见性状态,指定为'on'或者'离开',或作为数字或逻辑1(真的) or0(false). A value of'on'相当于真的, 和'离开'相当于false。Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of typematlab.lang.OnoffSwitchState.

  • 'on'- 显示对象。

  • '离开'- 隐藏对象而不删除它。您仍然可以访问不可见UI组件的属性。

To make your app start faster, set the可见的property to'离开'对于不需要在启动时显示的所有UI组件。

运营状态,指定为'on'或者'离开',或作为数字或逻辑1(真的) or0(false). A value of'on'相当于真的, 和'离开'相当于false。Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of typematlab.lang.OnoffSwitchState.

  • If you set this property to'on',App用户可以与组件交互。

  • If you set this property to'离开',该组件显示为暗淡,指示应用程序用户无法与之交互,并且它不会触发回调。

Tooltip, specified as a character vector, cell array of character vectors, string array, or 1-D categorical array. Use this property to display a message when the user hovers the pointer over the component at run time. The tooltip displays even when the component is disabled. To display multiple lines of text, specify a cell array of character vectors or a string array. Each element in the array becomes a separate line of text. If you specify this property as a categorical array, MATLAB uses the values in the array, not the full set of categories.

上下文菜单, specified as a上下文菜单使用的对象UIContextMenu.功能。右键单击组件时,请使用此属性显示上下文菜单。

Position

展开全部

按钮的位置和大小,指定为表单的向量[左下宽度]。This table describes each element in the vector.

元素 描述
left 距离父容器内左边缘的距离到按钮的外左边缘
底部 Distance from the inner bottom edge of the parent container to the outer bottom edge of the button
宽度 Distance between the right and left outer edges of the button
高度 按钮顶部和底部外边缘之间的距离

Position值相对于drawable areaof the parent container. The drawable area is the area inside the borders of the container and does not include the area occupied by decorations such as a menu bar or title.

所有测量均以像素为单位。

按钮的位置和大小, specified as a four element vector of the form[左下宽度]。所有测量均以像素为单位。此属性值与此属性相同Position财产。

此属性是只读的。

按钮的位置和大小,作为表单的四个元素矢量返回[左下宽度]。所有测量均以像素为单位。此属性值与此属性相同Position财产。

Horizontal alignment of the icon and text, specified as'中央','剩下', 或者'正确的'。这horizontal alignment is relative to the area inside the borders of the button. Setting this property when the text spans the full width of the button has no apparent effect in the UI.

Vertical alignment of the icon and the text, specified as'中央','top', 或者'底部'。这vertical alignment is relative to the area inside the borders of the button. Setting this property when the text height fills the height of the button has no apparent effect in the UI.

图标的位置相对于按钮文本,指定为'剩下','正确的','top', 或者'底部'。如果是Text属性是空的,那么the icon uses theHorizontalAlignmentVerticalAlignment属性而不是iconAlignment.财产。

布局选项,指定为aGridLayoutOptions目的。This property specifies options for components that are children of grid layout containers. If the component is not a child of a grid layout container (for example, it is a child of a figure or panel), then this property is empty and has no effect. However, if the component is a child of a grid layout container, you can place the component in the desired row and column of the grid by setting the柱子properties on theGridLayoutOptions目的。

例如,此代码将按钮放在其父网格的第三行和第二列中。

g = uigrivlayout([4 3]);B = UIBUTTON(G);B.Layout.Row = 3;b.layout.column = 2;

要使按钮跨越多行或列,请指定或者柱子属性作为双元素矢量。例如,此按钮跨栏2通过3:

b.layout.column = [2 3];

回调

展开全部

按钮按下回调,指定为其中一个值:

  • 功能手柄。

  • A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

当用户单击应用程序中的按钮时执行此回调。

This callback function can access specific information about the user’s interaction with the button. MATLAB passes this information in abuttonpusheddata.object as the second argument to your callback function. In App Designer, the argument is called事件。You can query the object’s properties using dot notation. For example,event.source.returns theButton目的。这buttonpusheddata.object is not available to callback functions specified as character vectors.

这following table lists the properties of thebuttonpusheddata.目的。

Property 价值
EventName 'buttonpushed'
来源 执行回调的组件

For more information about writing callbacks, seeWrite Callbacks in App Designer

对象创建函数,指定为其中一个值:

  • Function handle.

  • Cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.

  • 字符矢量包含有效的matlab表达式(不推荐)。MATLAB在基础工作区中评估此表达式。

有关将回调作为函数句柄,小区阵列或字符向量的更多信息,请参阅Write Callbacks in App Designer

此属性指定MATLAB创建对象时要执行的回调函数。MATLAB在执行之前初始化所有属性值CreateFcn.打回来。如果您没有指定CreateFcn.属性,然后matlab执行默认的创建功能。

设置CreateFcn.现有组件上的属性无效。

如果将此属性指定为函数句柄或单元格数组,则可以访问使用回调函数的第一个参数创建的对象。否则,使用gcbo.访问对象的函数。

Object deletion function, specified as one of these values:

  • Function handle.

  • Cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.

  • 字符矢量包含有效的matlab表达式(不推荐)。MATLAB在基础工作区中评估此表达式。

有关将回调作为函数句柄,小区阵列或字符向量的更多信息,请参阅Write Callbacks in App Designer

This property specifies a callback function to execute when MATLAB deletes the object. MATLAB executes thedeletefcn.callback before destroying the properties of the object. If you do not specify thedeletefcn.属性,然后matlab执行默认删除函数。

If you specify this property as a function handle or cell array, you can access the object that is being deleted using the first argument of the callback function. Otherwise, use thegcbo.访问对象的函数。

回调执行控制

展开全部

回调中断, specified as'on'或者'离开',或作为数字或逻辑1(真的) or0(false). A value of'on'相当于真的, 和'离开'相当于false。Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of typematlab.lang.OnoffSwitchState.

This property determines if a running callback can be interrupted. There are two callback states to consider:

  • 跑步回调是当前正在执行的回调。

  • 中断回调是一个回调,它试图中断运行的回调。

每当matlab调用回调时,回调尝试中断运行的回调(如果存在)。这Interruptibleproperty of the object owning the running callback determines if interruption is allowed.

  • A value of'on'允许其他回调中断对象的回调。中断发生在matlab处理队列的下一个点,例如何时存在drawnow,数字,Uifigure.,GetFrame.,等待, 或者暂停命令。

    • 如果是跑步callback contains one of those commands, then MATLAB stops the execution of the callback at that point and executes the interrupting callback. MATLAB resumes executing the running callback when the interrupting callback completes.

    • 如果运行回调不包含其中一个命令,则matlab完成在不中断的情况下执行回调。

  • A value of'离开'blocks all interruption attempts. TheBusyActionproperty of the object owning the interrupting callback determines if the interrupting callback is discarded or put into a queue.

Note

在这些情况下,回调中断和执行情况不同:

  • 如果中断回调是一个deletefcn.,CloseEquestfcn.或者SizechangedFCN.callback, then the interruption occurs regardless of theInterruptible适当的价值。

  • 如果正在运行的回调当前正在执行等待功能,无论的内容都会发生中断Interruptible适当的价值。

  • 计时器无论如何,对象根据计划执行Interruptible适当的价值。

发生中断时,MATLAB不保存属性或显示状态。例如,由此返回的对象GCA.或者GCF.command might change when another callback executes.

标准队列,指定为'队列'或者'取消'。这BusyActionproperty determines how MATLAB handles the execution of interrupting callbacks. There are two callback states to consider:

  • 跑步回调是当前正在执行的回调。

  • 中断回调是一个回调,它试图中断运行的回调。

Whenever MATLAB invokes a callback, that callback attempts to interrupt a running callback. TheInterruptible拥有运行回调的对象的属性确定是否允许中断。如果不允许中断,那么BusyActionproperty of the object owning the interrupting callback determines if it is discarded or put in the queue. These are possible values of theBusyAction财产:

  • '队列'- 将中断回调在运行回调完成后在队列中进行处理。

  • '取消'- 不执行中断回调。

此属性是只读的。

Deletion status, returned as an on/off logical value of typematlab.lang.OnoffSwitchState.

马铃薯sets the呈扭曲property to'on'当。。。的时候deletefcn.回调开始执行。这呈扭曲property remains set to'on'直到组件对象不再存在。

检查价值呈扭曲属性来验证object is not about to be deleted before querying or modifying it.

父母/孩子

展开全部

父容器, specified as a数字使用的对象Uifigure.功能,或其中一个子容器:标签,Panel,buttongroup., 或者GridLayout。If no container is specified, MATLAB calls theUifigure.function to create a new数字用作父容器的对象。

Visibility of the object handle, specified as'on','callback', 或者'离开'

This property controls the visibility of the object in its parent's list of children. When an object is not visible in its parent's list of children, it is not returned by functions that obtain objects by searching the object hierarchy or querying properties. These functions include得到,findobj.,clf, 和close。即使它们不可见,对象也有效。如果可以访问对象,则可以设置和获取其属性,并将其传递给对象上运行的任何功能。

Hupplvisibility价值 描述
'on' 该对象始终可见。
'callback' 从回调或通过回调调用的函数中可以看到该对象,但不是从命令行调用的函数中。此选项会阻止在命令行处访问对象,但允许回调函数访问它。
'离开' 对象始终是不可见的。此选项对于防止其他函数对UI的意外更改非常有用。设定Huppervisibility.'离开'至temporarily hide the object during the execution of that function.

Identifiers

展开全部

此属性是只读的。

图形对象的类型, returned as'Uibutton'

对象标识符,指定为字符向量或字符串标量。您可以指定一个唯一的标签作为对象的标识符的值。当您需要访问代码中其他地方的对象时,可以使用findobj.function to search for the object based on the标签价值。

用户数据,指定为任何MATLAB阵列。例如,您可以指定标量,向量,矩阵,单元格数组,字符数组,表或结构。使用此属性在对象上存储任意数据。

如果您在App Designer中工作,请在应用程序中创建公共或私有属性以共享数据而不是使用用户数据财产。有关更多信息,请参阅在App Designer应用程序中共享数据

See Also

Functions

Introduced in R2016a