NGUI下拉列表PopList
2017-12-21 19:46
555 查看
下拉列表简介
下拉表是通过用户点击后,罗列一些选项供用户选择,最终把选中的项显示出来。Unity中也有使用,例如UISprite组件的Type属性。![](https://nts.newbieol.com/static/k25/10_NGUI/10_%E4%B8%8B%E6%8B%89%E5%88%97%E8%A1%A8PopList/images/20160920140836.jpg)
下拉列表制作
本节课制作的效果如下:![](https://nts.newbieol.com/static/k25/10_NGUI/10_%E4%B8%8B%E6%8B%89%E5%88%97%E8%A1%A8PopList/images/20160920140557.jpg)
1)首先利用UIsprite制作下拉表的背景。
2)再制作好的背景图片下,添加一个Label组件,用来显示选项文字。
3)选中UISprite添加BoxCollider和PopList组件。
![](https://nts.newbieol.com/static/k25/10_NGUI/10_%E4%B8%8B%E6%8B%89%E5%88%97%E8%A1%A8PopList/images/20160920141304.jpg)
相关属性说明
* Options 列表项,每一行为一项。
* Default 默认项 程序运行时,默认选中显示的项。
* Position 下拉表出现的位置
* Auto 自动选择位置
* Above 在上方显示
* Below 在下方显示
* Alignment 下拉项文字对齐方式
* Automatic/Left/Center/Right/justified(自动扩展)
* OpenOn 下来表打开方式
* ClickOrTap(点击或轻触)/Right Click(右击)/Double Click(双击)/Manual(手动调用)
* Localized 是否本地化
Atlas组
用于设置下拉项的背景和和选中时的高亮效果。
![](https://nts.newbieol.com/static/k25/10_NGUI/10_%E4%B8%8B%E6%8B%89%E5%88%97%E8%A1%A8PopList/images/20160920142551.jpg)
Background:下拉表背景图
HeightLight:鼠标移动过程中选中项背景
Font组
用于设置显示下拉列表项中字体
![](https://nts.newbieol.com/static/k25/10_NGUI/10_%E4%B8%8B%E6%8B%89%E5%88%97%E8%A1%A8PopList/images/20160921094015.jpg)
Font 用于设置字体
Font-Size:设置文本大小
TextColor:文字的颜色
Padding:X 列表项水平内缩进
Padding:Y 列表项垂直方向间隔
PopList重要程序
1)如何获取Options中的列表项public class PopListDemo : MonoBehaviour { private UIPopupList list; // Use this for initialization void Start () { list = this.GetComponent<UIPopupList>(); //获取PopList的options项 foreach (string itemText in list.items) { print(itemText); } } }1
2
3
4
5
6
7
8
9
10
11
12
2)如何动态添加列表项
![](https://nts.newbieol.com/static/k25/10_NGUI/10_%E4%B8%8B%E6%8B%89%E5%88%97%E8%A1%A8PopList/images/20160921100700.jpg)
public class PopListDemo : MonoBehaviour { private UIPopupList list; // Use this for initialization void Start () { list = this.GetComponent<UIPopupList>(); //动态向options中添加项 for (int i = 0; i < 3; i++) { //通过AddItem添加项 list.AddItem("Item "+i); //通过RemoveItem删除项 //list.RemoveItem("Item1"); } } }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
3)动态获取当前选中的项
通过value属性可以获得当前列表项选中的值。
public class PopListDemo : MonoBehaviour { private UIPopupList list; // Use this for initialization void Start () { list = this.GetComponent<UIPopupList>(); //添加值改变回调 list.onChange.Add(new EventDelegate(onValueChange)); } void onValueChange() { print(list.value); } }
相关文章推荐
- Axure RP Pro - 相关问题 - 在规格文档中动态面板中的droplist下拉列表框部件会重复输出选项列表
- 利用列表控件(listcontrol)下面的东东做的 下拉列表联动 案例,我整了两天才整懂,别笑我笨,嘿嘿!
- Excel - 使用跨sheet定义Drop_List 下拉列表
- 列表:list[1],切片list[1:3],追加insert,修改,删除remove,del,pop,查找index,统计count,清空list.clear() 翻转list.reverse(),排序list.sort(),扩展list.extend,
- NGUI 拓展Poplist 插件
- react native 中下拉列表FlatList组件的讲解以及实例demo
- NGUI poplist使用
- 组合框(下拉列表)(Combo box(drop-down list))
- struts2 select标签对Action中传递过来的List集合生成下拉列表
- Axure RP Pro - 相关问题 - 原型中Droplist“下拉列表”部件在IE6中总显示在最前面
- list for ngui(Unity)列表
- ASP.NET.MVC--注解和反射将Enum转换List<SelectListItem>为@Html.DropDownListFor()下拉列表的通用方法
- NGUI-----poplist值的获取代码(可操作控制数据库)
- jsp接收到controller传来的list集合 怎么把list集合里的值添加到动态生成的下拉列表,求救。。。。急急急
- Python列表list内建函数用法实例分析【insert、remove、index、pop等】
- 64、通过PickListValuesUtil,Schema查看下拉列表中的值
- unity_NGUI系统学习(十一)_PopupList下拉列表(弹出列表)的创建和使用
- NGUI文本列表TextList
- 详解Android的Socket通信、List加载更多、Spinner下拉列表
- 貌似淘宝下拉PopWindow筛选【动画、列表、位置】