Friday, February 12, 2010

resize or scale UIImage

hi,

we can scale the UIImage to any size using the follwing method

add this code to your .h file

@interface UIImage (INResizeImageAllocator) + (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize; - (UIImage*)scaleImageToSize:(CGSize)newSize; @end


add the following to .m file

@implementation UIImage (INResizeImageAllocator) + (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize; { UIGraphicsBeginImageContext( newSize ); [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } - (UIImage*)scaleImageToSize:(CGSize)newSize { return [UIImage imageWithImage:self scaledToSize:newSize]; } 


e.g to resize an image
self.resizeimage = [UIImage imageWithImage:actual_image scaledToSize:CGSizeMake(65.0f, 65.0f)];

Thursday, February 11, 2010

UIWebView : load local html file

Formatting UITextView

There is no feature to format the text in UITextView

We can use the UIWebView to display the formatted text
The easy two methods are :

1. - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
2. - (void)loadRequest:(NSURLRequest *)request

1.
use the html formatted text as input.
e.g:
NSString *htmlText = @"<html><head><meta name=""viewport"" content=""width=320""/></head><body><h3>Header</h3><p>Just for testing n;</p></body</html>";
[webView loadHTMLString:htmlText baseURL:[NSURL URLWithString:@"http://www.apple.com"]];

2. Or we can load a local html file
e.g:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];

Tuesday, February 9, 2010

Dynamic Height for UITextView / UILabel / UITableViewCell

we can use this for calculating the height taken by a UILabel or UITextView or we can use this same method to calculate the height of cell according to its content..

CGRect frame1 = CGRectMake(5.0, 100.0, 300.0, 75.0 ); UITextView *textView = [[UITextView alloc] initWithFrame:frame1]; textView.font = [UIFont systemFontOfSize:17.0]; NSString *str = @"The Lord takes care of me as his sheep; I will not be without any good thing."; CGSize textSize = { 300.0f, 9999.0f }; CGSize size1 = [str sizeWithFont:textView.font constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap]; textView.text = str; frame1.size.height = size1.height; textView.frame = frame1; [self.view addSubview:textView]; [textView release];



For UITableView
we can use like
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//calculate the height of the text displayed on this cell using the above method
return MAX(size1.height, kMinRowHeight);
}

Macworld 2010 Feb 9 -13 @ San Francisco

Macworld 2010 is a five day celebration that will educate, entertain, and immerse you in the Mac community. Macworld offers access to hundreds of Mac products and services, paired with expert advice, demonstrations and instruction. Macworld conference programs feature industry leading minds, presenting cutting edge product training on the topics you most want to see. Whether you are a creative professional or a Mac IT pro, Macworld has the conference content, special presentations, exhibit hall highlights and experiences that meet your specific Mac needs.

Read More