This module extends the Ti SDK, allowing to add "drop shadow" functionalities to any View object you create.
The code implementing this feature has been originally posted by Javier Rayon here.
The module is licensed under the MIT license.
TITANIUM 2 SUPPORT: Titanium 2 introduces some breaking layout changes. On iOS, now views are clipped to their bounds. Since shadows are dropped outside the view bounds, this affects seriously to this module. We tried to avoid this behavior, but in some cases the shadow does not work as expected. While we find a solution, consider that in these cases:
- Using Ti.UI.SIZE in a parent view, could cut the shadows of its children.
- A view with solid background and with children views can not drop shadow itself (but the children will do)
Update: to get shadows working correctly on titanium 2 or higher, add the shadow after the postlayout event. For example:
var postLayoutCallback = function(e) {
view.removeEventListener('postlayout', postLayoutCallback); //remove to avoid repeated calls
view.setShadow({ //add the shadow
shadowOffset:{x:0, y:6},
shadowRadius:4,
shadowOpacity:0.5
});
}
view.addEventListener('postlayout', postLayoutCallback);
First, you must have your XCode and Titanium Mobile SDKs in place, and have at least read the first few pages of the iOS Module Developer Guide from Appcelerator.
The build process can be launched using the build.py script that you find in the module's code root directory.
As a result, the ti.viewshadow-iphone-0.3.zip file will be generated.
NOTE: if your Titanium sdk resides in the root /Library/Application Support/Titanium/
directory, you need to change the value of the TITANIUM SDK
variable in titanium.xcconfig
You can either copy the module package (ti.viewshadow-iphone-0.3.zip) to $HOME/Library/Application\ Support/Titanium
and reference the module in your application (the Titanium SDK will automatically unzip the file in the right place), or manually launch the command:
unzip -uo ti.viewshadow-iphone-0.3.zip -d $HOME/Library/Application\ Support/Titanium/
NOTE: if your Titanium sdk resides in the root /Library/Application Support/Titanium/
directory, change the above command accordingly
Simply add the following lines to your tiapp.xml
file:
<modules>
<module version="0.3" platform="iphone">ti.viewshadow</module>
</modules>
and add this line in your app.js file:
require('ti.viewshadow');
The module provides no public api. It's simply used for extending the TiUIView class provided by the Ti SDK with additional functionality.
0.3:
-
Added support for retina displays, both iPhone and iPad
-
Added (not full) support for Titanium 2.
0.2:
-
added colorShadow property
-
performance improved using rasterization and shadowPath
0.1:
- first version, supporting shadowOffset, shadowRadius and shadowOpacity properties.
- Javier Rayon: https://github.com/jaraen (@jrayon)
- Olivier Morandi: https://github.com/omorandi (@olivier_morandi)
- Daniel Tamas: https://github.com/rborn (@dan_tamas)
Copyright (c) 2012 Javier Rayon, Olivier Morandi, Daniel Tamas
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.