views:

27

answers:

1

I have an image I am loading into a UIWebView as such:

NSData *data2 = [[NSData alloc] initWithBytes:sqlite3_column_blob(selectstmt, 7) length:sqlite3_column_bytes(selectstmt, 7)];
if(data2 != nil) {                  
    [webView loadData:data2 MIMEType:@"image/png" textEncodingName:nil baseURL:nil];
    webView.backgroundColor = [UIColor clearColor];             
}
[data2 release];

My question is when the content is loaded in, it is always justified to the top left. Is there any way to justify the content to a different position, say top center, or center center?

+1  A: 

It's a web view; load HTML with the image and handle the layout in HTML.

i.e.

NSString * myImageHTML = [NSString stringWithFormat:@"<html><head></head><body><center><img
src=\"data:%@\"/></center></body></html>", image];

You can embed base64 encoded images in HTML and it will be rendered. The above code is untested, and you haven't made it clear exactly how your image is stored in your application, so this is speculative. The short answer is: use HTML to format it.

But, all that aside, why aren't you using a UIImageView instead? It's perfectly geared to doing what you want, and is a better choice that a UIWebView imo.

dannywartnaby