removeStyle
说明
示例
从树中删除所有样式
首先,向一个树添加两个样式。
fig = uifigure; fig.Position = [100 100 250 350]; t = uitree(fig); n1 = uitreenode(t,'Text','Fruits'); n11 = uitreenode(n1,'Text','Banana'); n12 = uitreenode(n1,'Text','Cherry'); n2 = uitreenode(t,'Text','Vegetables'); n21 = uitreenode(n2,'Text','Broccoli'); n22 = uitreenode(n2,'Text','Lettuce'); expand(t) s1 = uistyle('FontColor',[0 0.4 0.7]); s2 = uistyle('FontColor',[0.1 0.5 0.1]); addStyle(t,s1,'level',2); addStyle(t,s2,'node',[n2 n21 n22]);
然后,删除这两个样式以将树还原为其默认外观。
removeStyle(t)
从表中删除样式子集
向表 UI 组件添加多个样式,然后删除其中一些样式。
首先,创建一个表 UI 组件,并向它的不同部分添加样式。
fig = uifigure; fig.Position = [500 500 720 230]; uit = uitable(fig); uit.Data = randi([-20,20],7); uit.Position = [20 30 680 185]; [row,col] = find(uit.Data<0); s1 = uistyle; s1.BackgroundColor = 'cyan'; addStyle(uit,s1,'column',[1 3 5]) s2 = uistyle; s2.FontColor = 'red'; s2.FontWeight = 'bold'; addStyle(uit,s2,'cell',[row,col]) s3 = uistyle('BackgroundColor','green'); addStyle(uit,s3,'row',[3 4]) addStyle(uit,s1,'column',7)
现在,删除行和列样式。首先,查询该表的 StyleConfigurations
属性的值。
uit.StyleConfigurations
ans=4×3 table
Target TargetIndex Style
______ _____________ ___________________________
1 column { 1x3 double} [1x1 matlab.ui.style.Style]
2 cell {20x2 double} [1x1 matlab.ui.style.Style]
3 row { 1x2 double} [1x1 matlab.ui.style.Style]
4 column {[ 7]} [1x1 matlab.ui.style.Style]
StyleConfigurations
属性值显示顺序号为 1
和 4
的样式影响列的样式,行样式是添加到表中的第三个样式。通过指定样式顺序号 1
、3
和 4
删除样式。
removeStyle(uit,[1 3 4])
输入参数
comp
— UI 组件
Table
对象 | Tree
对象 | ListBox
对象 | DropDown
对象
UI 组件,指定为以下 UI 组件之一:
使用
uitable
函数创建的Table
对象使用
uitree
函数创建的Tree
对象使用
uilistbox
函数创建的ListBox
对象使用
uidropdown
函数创建的DropDown
对象
该组件对象必须以使用 uifigure
函数创建的图窗或其子容器之一为父级。
ordernum
— 样式顺序号
正整数 | 正整数向量
样式顺序号,指定为正整数或正整数向量。要确定当前应用于表的样式及其添加顺序,请查询 StyleConfigurations
属性的值。
当您删除上次添加的样式之外的样式时,其余样式会向上移动以填补空缺。如果未指定样式顺序号,将从 UI 组件中删除所有样式。
示例: removeStyle(comp,2)
删除 comp.StyleConfigurations
返回的列表中的第二个样式。
示例: removeStyle(comp,[1 3 5])
删除 comp.StyleConfigurations
返回的列表中的第一个、第三个和第五个样式。
示例: removeStyle(comp)
从 UI 组件中删除所有样式。
版本历史记录
在 R2019b 中推出R2023a: 从列表框或下拉 UI 组件中删除样式
要从列表框或下拉 UI 组件中删除样式,请将 ListBox
或 DropDown
对象指定为 removeStyle
函数的第一个参量。
R2021b: 从树 UI 组件中删除样式
要从树中删除样式,请将 Tree
对象指定为 removeStyle
函数的第一个参量。
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)