Giter VIP home page Giter VIP logo

segmentedcontrol's Introduction

#Tabbed Bar Widget

Cross-platform segmented control (TabbedBar) widget for Appcelerator Titanium apps, by @skypanther

iPhone iPhone

This is an Alloy widgetized version of my old segmented control component with some updated code and options.

Note: This widget uses a custom component on both iOS and Android. In other words, it does not fall back to Ti.UI.iOS.TabbedBar.

Installation and usage

Recommended

$ gittio install com.skypanther.segmentedcontrol

###Manual method (works, but why not use gittio?):

  1. Download this repo (git clone, zip, whatever)
  2. Copy the widgets/com.skypanther.segmentedcontrol to your project's widgets folder
  3. Update your app/config.json to add:
"dependencies": {
    "com.skypanther.segmentedcontrol": "1.0.6"
}

In your XML file, add the widget:

<Widget src="com.skypanther.segmentedcontrol" id="tbar" top="100"/>

Add styling as desired in your tss:

"#tbar": {
	borderRadius: 6,
	borderColor: "#C73C45",
	selectedButtonColor: "#C73C45",
	unselectedButtonColor: "#fff", 
	selectedButtonTextColor: "#fff",
	unselectedButtonTextColor: "#C73C45",
	index: 0,
	withDividers: true,
	font: {
		fontWeight: 'bold',
		fontSize: '15'
	}
}

Initialize it in the controller:

$.tbar1.init(['One', 'Two', 'Three'], callback);

function callback(e) {
	alert('You clicked button ' + (e.index+1));
}

// Get current selected value
alert($.tbar1.getIndex());

Styling options

You can set these style options in the TSS or in your XML tag.

Property Description Default
selectedButtonColor background color of the
selected button
#d9bc1b (yellow)
unselectedButtonColor background color of buttons
that are not selected
#226e92 (blue)
selectedButtonTextColor color of text on the selected
button
#fff
unselectedButtonTextColor color of text on unselected
buttons
#000
disabledTextColor color of text on a disabled
button
#aaa (light grey)
disabledButtonBackgroundColor background color of a
disabled button
#444 (dark grey)
font font properties of the button
labels
{fontFamily: 'Avenir-Light', fontSize: 11} (ios)
{fontWeight: 'normal', fontSize: '15dp'} (android)
withDividers whether to add dividers between button (color matches selected backgroundcolor) false

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.

Methods

Method Notes
init(labels, callback) You must call this method to initialize the control, passing to it an array of labels and a function to be called when a button is tapped. That function will receive an object whose index property is the number of the button that was tapped
select(num) Selects the button specified
getIndex() Gets the current selected button
setIndex(num) Synonym for select()
deselect(num) Deselects (unselects) the button specified
enable() Enables click events for the whole control
disable() Disables click events for the whole control
deselectAll() Deselects all the buttons in the control
disableButton(num) Disables the specified button, making it unclickable while the rest remain clickable
enableButton(num) Enables the specified button, making it clickable.
disableAllButtons() Disable all buttons, making them all unclickable. Essentially the same as disable()
enableAllButtons() Enable all buttons, making them all clickable unless you have called disable(). In that case, you'd need to call enable()

History

  • 18-Mar-2016: Ver 1.0.6 resolves a bug with select (not deselecting old value) and adds getIndex()
  • 3-Mar-2016: Ver 1.0.5 resolves #5, yet another attempt! (it would help if I owned more iOS devices, donations welcome ๐Ÿ˜€)
  • 29-Feb-2016: Ver 1.0.4 resolves #5, thanks Will Dent! (last button in set not filling entire area on iPhone 6s+)
  • 16-Feb-2016: Ver 1.0.3 resolves last button in set not filling entire area on iPhone 6s+
  • 08-Feb-2016: Ver 1.0.2 resolves issue where selecting/setIndexing a button didn't deselect the other buttons
  • 05-Feb-2016: Ver 1.0.1 resolves layout issues on larger iOS devices when using percentage-based widths
  • 29-Jan-2016: Initial release of the widget-ized version of my old Classic-style component
  • Ancient history, like 2011, initial release with a few interim releases thereafter

Limitations

  • I have not tested this with more than 4 buttons. Too many and it will surely fail.
  • I haven't tested it on a tablet. Layout might be screwed up.
  • I'm pretty sure it won't handle rotation of the device well.
  • It doesn't support anything fancy, like icons instead of text on the buttons. Note: it will support icon fonts for your text labels, so you can achieve a similar effect.

Contributions are welcome!

#License / Copyright

ยฉ 2016 Tim Poulsen

MIT licensed

segmentedcontrol's People

Contributors

mcvendrell avatar skypanther avatar willdent avatar

Watchers

 avatar  avatar  avatar

Forkers

elkouriabdelali

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.