Created
September 3, 2013 17:49
-
-
Save tzmartin/6427217 to your computer and use it in GitHub Desktop.
Native dynamic height calculation for UIViews in Titanium Mobile SDK. Useful for situations where getSize(), getRect() or postLayout event is not sufficient. Typically needed when view dimensions are set to Ti.UI.FILL or Ti.UI.SIZE. Add this method to TiUiLabelProxy.m, TiUITableViewProxy.m Reference: http://developer.appcelerator.com/question/14…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(id)suggestHeight:(id)arg | |
{ | |
CGFloat height = 0; | |
// resolve arg | |
if (arg != nil && [arg isKindOfClass:[NSArray class]]) | |
{ | |
NSArray *args = (NSArray *)arg; | |
if (args.count > 0) | |
arg = [args objectAtIndex:0]; | |
else | |
arg = nil; | |
} | |
// if no arg then use defined width for the label | |
if (arg == nil) | |
arg = [self valueForKey:@"width"]; | |
// if arg set then compute the width | |
if (arg != nil) | |
{ | |
TiDimension d = [TiUtils dimensionValue:arg]; | |
CGFloat width = 0; | |
if (d.type == TiDimensionTypeDip) | |
width = d.value; | |
else if (d.type == TiDimensionTypePercent && self.parent != nil) | |
width = [self.parent.size.width floatValue] * d.value; | |
if (width>0) | |
height = [self contentHeightForWidth:width]; | |
} | |
return [NSNumber numberWithFloat:height]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment