`
LiYunpeng
  • 浏览: 950871 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

Flex4中Slider 自定义Flex3中的labels样式

    博客分类:
  • Flex
阅读更多
转自
http://prsync.com/adobe/creating-a-custom-skin-to-add-tics-and-labels-to-spark-sliders-7788/

There has been some recent discussion over how to get tics and labels on Spark Sliders. Halo Sliders contained built in support for tics and labels, however, this feature does not yet exist for Spark Sliders. While built in support may be added in the future, for the time being the way to get tics and labels for a Spark Slider is to implement a custom skin. With the new Spark skinning architecture, this is relatively easy to do.

For example, to get labels for an HSlider, you could simply copy, rename, and then modify the HSliderSkin.mxml file.

First, copy HSliderSkin.mxml and give it a new name, i.e. CustomHSliderSkin.mxml. When you define the HSlider in your application, use the skinClass style to point to the new skin.

<s:HSlider skinClass="CustomHSliderSkin"/>

This assumes that the CustomHSliderSkin.mxml file is in the same directory as the application file. If it is in another directory, the full path to the file must be specified. For example, if the CustomHSliderSkin.mxml file were in a sub-directory named "skins", you would specify it as "skins.CustomHSliderSkin".

In the CustomHSliderSkin file you can add labels in any number of ways. For this example I will use the SimpleText component, but really anything from a BitmapGraphic to a Rect could be used.

To add a label that displays the string "min" to the left hand side of the HSlider, you can define a SimpleText component as follows:

<s:SimpleText id="leftLabel" left="0" top="0" text="min"/>

Since the SimpleText component above has been positioned flush with the left hand side of the container, the HSlider track needs to be moved over so that they do not overlap. To do so, set the "left" style constraint on the track to a value that gives the label enough room to be displayed and provides the spacing that you find aesthetically pleasing. In this case a value of 30 would be sufficient to display the label "min".

Using the same approach, a label can be added to the right side of the HSlider. For example:

<s:SimpleText id="rightLabel" right="0" top="0" text="max"/>

Again, space needs to be given to ensure that the HSlider track and the right side SimpleText component do not overlap. In this case, setting the "right" style constraint on the HSlider track to 30 will work as well.

The skin would therefore contain the following:

<!-- Defines the left label -->
<s:SimpleText id="leftLabel" left="0" top="0" text="min"/>

<!--- Defines the skin class for the CustomHSliderSkin's track. The default skin class is CustomHSliderTrackSkin. -->
<s:Button id="track" left="30" right="30" top="0" bottom="0" skinClass="skins.CustomHSliderTrackSkin" />

<!--- Defines the skin class for the CustomHSliderSkin's thumb. The default skin class is CustomHSliderThumbSkin. -->
<s:Button id="thumb" top="0" bottom="0" width="11" height="11" skinClass="skins.CustomHSliderThumbSkin" />

<!-- Defines the right label -->
<s:SimpleText id="rightLabel" right="0" top="0" text="max"/>

By modifying the style constrains used above you can move the labels above or below the HSlider track in whatever way you want. For example, for labels on top of the HSlider, you could simply move the Slider track and thumb down by setting the top style constraint for both to 20, and leaving left and right as 0. In that case, the skin would contain the following:

<!-- Defines the top left label -->
<s:SimpleText id="leftLabel" left="0" top="0" text="min"/>

<!--- Defines the skin class for the CustomHSliderSkin's track. The default skin class is CustomHSliderTrackSkin. -->
<s:Button id="track" left="0" right="0" top="20" bottom="0" skinClass="skins.CustomHSliderTrackSkin" />

<!--- Defines the skin class for the CustomHSliderSkin's thumb. The default skin class is CustomHSliderThumbSkin. -->
<s:Button id="thumb" top="20" bottom="0" width="11" height="11" skinClass="skins.CustomHSliderThumbSkin" />

<!-- Defines the top right label -->
<s:SimpleText id="rightLabel" right="0" top="0" text="max"/>

In this way, labels of any type can be very quickly added to an HSlider, and of course the same approach can be used to VSlider.

To add tics, a similar approach is used.

Like labels, tics can be implemented in any number of ways. The most straight forward way is to simply insert them manually at the desired position on the Slider track.

Anything can be used as a tic - a BitmapGraphic, a Rect, a Line - anything the developer chooses. In keeping with the label example above, the following method can be used to insert tics using a SimpleText component. The hardest part of adding tics is determining where they should be placed. In the example below, the x property is used to specify the location of the tic.

These tics would be useful for an HSlider with the snapInterval property set to 25 since they are positioned in a rough correspondence to multiples of 25 on a HSlider track with a minimum of 0 and maximum of 100, i.e. the HSlider would look like this in the application:

<s:HSlider minimum="0" maximum="100" snapInterval="25" skinClass="CustomHSliderSkin"/>

CustomHSliderSkin.mxml would then contain the following:

<!-- Define tics -->
<s:SimpleText text="|" x="34"/>
<s:SimpleText text="|" x="66"/>
<s:SimpleText text="|" x="99"/>
<s:SimpleText text="|" x="131"/>
<s:SimpleText text="|" x="164"/>

<s:SimpleText id="leftLabel" left="0" top="12" text="min"/>

<!--- Defines the skin class for the CustomHSliderSkin's track. The default skin class is CustomHSliderTrackSkin. -->
<s:Button id="track" left="30" right="30" top="12" bottom="0" skinClass="spark.skins.spark.HSliderTrackSkin" />

<!--- Defines the skin class for the CustomHSliderSkin's thumb. The default skin class is CustomHSliderThumbSkin. -->
<s:Button id="thumb" top="12" bottom="0" width="11" height="11" skinClass="spark.skins.spark.HSliderThumbSkin" />

<s:SimpleText id="rightLabel" right="0" top="12" text="max"/>

With this approach, tics and labels can be manually added to a Slider skin.
分享到:
评论

相关推荐

    Flex4 Video Slider 使用

    在本文中,我们将深入探讨如何在Flex4中有效地利用`Video`组件和`Slider`组件。Flex4是一个强大的开发框架,允许开发者创建丰富的互联网应用程序,其中包括多媒体处理和用户交互功能。`Video`组件用于播放视频内容,...

    slider.zip

    在本示例中,"slider.zip"包含了一个自定义样式的`slider`实现,通过覆盖默认样式,使得设计更加灵活且个性化。这种方式并不直接修改`slider`组件自身的样式属性,而是利用`view`组件进行层级覆盖,从而实现定制化的...

    WPF滑块控件(Slider)的自定义样式

    主要介绍了WPF滑块控件(Slider)的自定义样式的相关知识,本文给大家介绍的非常详细,具有一定的参考借鉴价值 ,需要的朋友可以参考下

    slider多滑块拖动条

    3. **拖动条的区分间隔**:在“slider多滑块拖动条”中,用户可以设置滑动条上的间隔,这决定了滑动条上刻度的分布,使得用户在查看数值区间时更加直观。例如,可以设置滑动条上的刻度为均匀间隔,以清晰展示每个...

    QT使用图片实现的Slider自定义控件.rar

    此自定义控件不使用原生的QSlider,完全重新写的一个Slider功能。可实现SetChannelImage传入Slider背景图,SetThumbImage传入推子图,SetRange设定有效值范围,便可高效实现Slider功能。

    flex4做的MP3播放器

    3. **MX和Spark组件**: Flex4引入了Spark和MX两套组件集,Spark组件更加现代且可自定义,而MX组件则兼容早期版本。在播放器界面设计时,可能会使用Spark组件如Button、Slider等来实现播放、暂停、音量控制等功能。 ...

    WPF 快速了解并实现美观的Slider自定义控件-Slider详解-示例-效果

    本文源码

    Flex 4 进度条的皮肤

    在Flex 4中,皮肤是界面组件外观的关键元素,可以自定义以满足特定设计需求。进度条是用户界面中常见的组件,用于表示任务的完成程度或加载状态。本文将深入探讨如何在Flex 4中创建和定制进度条的皮肤。 首先,我们...

    Flex4实现音频播放器-显示语音波形

    在Flex4中,皮肤和样式也是重要的一环。我们可以为播放器组件定制外观,比如改变按钮的颜色、形状等。通过定义CSS样式表和使用Skin类,我们可以实现高度自定义的界面设计。 在实现过程中,还需要注意一些实际问题,...

    flex 图片轮播效果

    在Flex中,我们可以通过加载这个XML文件,解析其内容,并将每张图片的URL绑定到一个Image组件上。同时,我们可以创建一个定时器或计时器事件,每隔一定时间自动切换图片。用户还可以通过点击左右箭头或者滑动来手动...

    flex4新特性展示(中文版)

    相比于Flex 3中的Halo布局引擎,Spark布局引擎提供了更多的灵活性和更高的性能。通过引入新的布局策略和算法,开发者可以在创建复杂用户界面的同时确保应用的响应速度和流畅度。 - **新的布局策略**:Flex 4引入了...

    Flex仿苹果风格的滑块开关控件

    在MXML中,我们可以看到如何创建和配置Slider实例,以及如何应用自定义样式和事件监听器。此外,项目的源代码可能还包含了CSS文件,用于定义滑块的视觉样式。 总的来说,创建Flex仿苹果风格的滑块开关控件需要对...

    FLEX3程序的皮肤集合

    1. **组件皮肤**:Flex3中的每个UI组件,如Button、Slider、TabNavigator等,都有预定义的皮肤。这些皮肤由MXML或ActionScript3代码定义,包含组件的各个部分,如背景、边框、文本样式等。通过替换这些皮肤,可以...

    Flex4 的 苹果风格 弹出窗口

    基于国外的 MacPopup 苹果风格,自己很喜欢,但是国外提供的 该控件 是基于flex 3的 ,所以在目前flex4为主流的 sdk 情况下,会出现错误。本控件 已经做了修正。可以直接运行。请指导。

    自定义slider

    在iOS和Android等移动应用开发中,`Slider`(滑块)是一种常见的用户界面元素,用于让用户通过拖动滑块来选择一个介于最小值和最大值之间的数值。本教程将深入探讨如何自定义`Slider`,使其外观更加美观,以图片化的...

    flex MP3播放器

    4. 播放进度条:展示当前播放进度,使用Slider组件并与播放时间关联。 5. 歌词显示区域:显示歌词同步内容,可以是Text或RichText组件,实时更新歌词文本。 6. 波形显示区:用图形表示音乐的波形,可能自定义绘图或...

    wpf自定义slider

    在WPF中,可以通过继承现有的控件并重写或扩展其属性、方法和样式来实现自定义。对于Slider,可能需要覆盖它的模板(Template)来更改视觉表示。 4. **资源字典与样式(Styles and Templates)** 自定义Slider...

    WPF自定义进度条控件和slider 滑块控件

    与`ProgressBar`类似,`Slider`的样式也是可自定义的。我们可以定制滑块的轨道颜色、滑块形状、手柄大小,甚至滑动时的视觉反馈。比如,你可以创建一个带有自定义指示器的`Slider`,当用户调整值时,指示器会显示...

    iOS 自定义滑动分段选择Slider

    本篇将深入探讨如何在iOS应用中自定义滑动分段选择器(Slider),创建出独特且吸引用户的交互体验。 一、滑动分段选择器的基本概念 滑动分段选择器通常由两个部分组成:一个可滑动的 thumb(或handle)和一个显示...

    custom-slider:自定义滑块

    自定义滑块 埃斯特上课联合国PROYECTO去实习课阙他realizado科莫inspiración人版本视频去胡安·安德烈斯·恩 。 实践技术的实践经验禁止在公共场所发信给任何未成年人的问题。 Tecnologíasempleadas HTML(con ...

Global site tag (gtag.js) - Google Analytics