项目作者: Bhushankumar-pawar

项目描述 :
An Alloy widget Segmented Control for Titanium / Appcelerator (Cross-platform )
高级语言: JavaScript
项目地址: git://github.com/Bhushankumar-pawar/Segmented_Control.git
创建时间: 2018-04-27T19:46:03Z
项目社区:https://github.com/Bhushankumar-pawar/Segmented_Control

开源协议:

下载


SEGMENTED CONTROL Appcelerator Titanium Appcelerator Alloy

This is a widget for the Alloy MVC framework of Appcelerator‘s Titanium platform.

segmented control is a linear set of two or more segments, each of which functions as a mutually exclusive button. Within the control, all segments are equal in width.

3-Types of segmented control:


  • borderSegment
    borderSegment




  • flatSegment
    flatSegment



  • scrollingFlatSegments - Flat segment for more than 4 segments
    scrollingFlatSegments

Installation and usage

  1. $ gittio install BhushanP.SEGMENTED_CONTROL

Manual method

  • Download this repo (git clone / download zip)
  • Copy the widgets to your project’s widgets folder
  • Update your app/config.json to add:
  1. "dependencies": {
  2. "BhushanP.SEGMENTED_CONTROL": "1.0"
  3. }




Example
Complete code base and demonstrating the usage of the widget.

In your XML file, add the widget:

  1. <View id="segmentedView" width="70%" top="10dp" height="35dp" backgroundColor="white">
  2. <Widget id="topsegmentedControl" src="BhushanP.SEGMENTED_CONTROL" ></Widget>
  3. </View>
  4. <ScrollableView id="topScrollableView" onScrollend="scrollEnd" top="10dp" height="100%">
  5. <!-- Add Content views as per your segments. Add onScrollend event if you want to change the state of a segment on scroll change. Please take care content of ScrollableView will match with array passed to initSegmentedControl function as 1st argument -->
  6. </ScrollableView>

Initialize it in the controller:

  1. init();
  2. function init() {
  3. Ti.API.log("[segmentControl]>>>[init]");
  4. $.topsegmentedControl.initSegmentedControl(["segment 1", "segment 2","segment 3"], optionTopViewSingleTab, {
  5. "borderColor" : "#0080B0",
  6. "bgColor" : "transparent",
  7. "selectedBgColor" : "#0080B0",
  8. "labelColor" : "#0080B0",
  9. "selectedLabelColor" : "#FFFFFF",
  10. "removeAllFlag" : true,
  11. "widgetType":"borderSegment"
  12. });
  13. optionTopTabArray = $.topsegmentedControl.getSegmentsArray();
  14. }
  15. function optionTopViewSingleTab(e) {
  16. Ti.API.log("[segmentControl]>>>[optionTopViewSingleTab]");
  17. Ti.API.log("optionTopViewSingleTab");
  18. SegmentscrollEnabled = true;
  19. $.topScrollableView.scrollToView(optionTopTabArray.indexOf(this));
  20. $.topsegmentedControl.selectTabFromController(this);
  21. }//End of optionViewSingleTab
  22. /**
  23. * Event Handler: for Scrollable region.
  24. */
  25. var scrollsegments = true;
  26. function scrollEnd(e) {
  27. Ti.API.log("[segmentControl]>>>[scrollEnd]");
  28. var scrollEnabled = SegmentscrollEnabled ? false : true;
  29. $.topsegmentedControl.selectTabFromController(optionTopTabArray[e.currentPage], scrollEnabled);
  30. setTimeout(function() {
  31. SegmentscrollEnabled = false;
  32. }, 1E1);
  33. }//End of scrollEnde

Styling options

You can set these style options in the js

Property Description style Default
selectedBgColor slected background color of the segment
selected segment
#0080B0 ‘#006BA3’
borderColor border color of segment
border of segment
0080B0 #FFFFFF
bgColor background color of the segment
segment backgroundColor
transparent transparent
selectedLabelColor color of text on segment
Selected sgements label color
#FFFFFF white
widgetType type of segment controll
borderSegment, flatSegment, scrollingFlatSegments
borderSegment, flatSegment, scrollingFlatSegments none
horizontalLineColor horizontal line color of segment
applicable for flatSegment, scrollingFlatSegments
#0080B0 none
tabWidth tab width of segment
applicable for flatSegment, scrollingFlatSegments
100 Fixed width

Additionally, most other properties you set on the widget (via its xml tag or id/class selectors) will be passed down to the widget’s components.

Limitations

  • Array passed to initSegmentedControl function and child content of ScrollableView view must be same. This Array decides the segments in the widget and ScrollableView’s 1st level children are referenced by segments.

Contributions are welcome!

License

  1. Copyright 2017 Bhushankumar Pawar
  2.  
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6.  
  7. http://www.apache.org/licenses/LICENSE-2.0
  8.  
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.