| Platform | Since |
|---|---|
| iPhone | 0.9 |
| iPad | 0.9 |
| Mobile Web | 1.8 |
A background gradient for the view.
A gradient can be defined as either linear or radial. A linear gradient
varies continuously along a line between the startPoint and endPoint.
A radial gradient is interpolated between two circles, defined by startPoint
and startRadius and endPoint and endRadius respectively.
The start and end points and radius values can be defined in device units, in the view's coordinates, or as percentages of the view's size. Thus, if a view is 60 x 60, the center point of the view can be specified as:
{ x: 30, y: 30 }
Or: { x: '50%', y: '50%' }
When specifying multiple colors, you can specify an offset value for each color, defining how far into the gradient it takes effect. For example, the following color array specifies a gradient that goes from red to blue back to red:
colors: [ { color: 'red', offset: 0.0}, { color: 'blue', offset: 0.25 }, { color: 'red', offset: 1.0 } ]
The following code excerpt creates two views, one with a linear gradient and one with a radial gradient.
var win1 = Titanium.UI.createWindow({ title:'Tab 1', backgroundColor:'#fff', layout: 'vertical' }); var radialGradient = Ti.UI.createView({ top: 10, width: 100, height: 100, backgroundGradient: { type: 'radial', startPoint: { x: 50, y: 50 }, endPoint: { x: 50, y: 50 }, colors: [ 'red', 'blue'], startRadius: '90%', endRadius: 0, backfillStart: true } }); var linearGradient = Ti.UI.createView({ top: 10, width: 100, height: 100, backgroundGradient: { type: 'linear', startPoint: { x: '0%', y: '50%' }, endPoint: { x: '100%', y: '50%' }, colors: [ { color: 'red', offset: 0.0}, { color: 'blue', offset: 0.25 }, { color: 'red', offset: 1.0 } ], } }); win1.add(radialGradient); win1.add(linearGradient); win1.open();