user1127421
user1127421

Reputation: 21

UIWebView - Centering Two Images Xcode 4.2

I am trying to get two images to center in UIWebview.

The user selects from a choice of eight images.

The next screen displays text above the two images, then the two images and then some more text below the two images.

I am new to Xcode and I can't seen to figure out how to center the two png files. They currently align left. There is a big gap of space to the right of them. I've tried setting align right and align center but haven't found the proper place to do these settings.

Can what I am trying to do be done?

How?

Upvotes: 1

Views: 973

Answers (1)

Nick Lockwood
Nick Lockwood

Reputation: 40995

When you say "in a UIWebview", do you mean in the HTML displayed in the webview? if so you'd be better off asking this as a css/html question than an iOS one as it has little to do with iOS.

If you mean in the web view html, you can wrap the image in a <center> tag, or put style="display:block;margin:0 auto" on the <img> tag.

If you mean in native code (although I'm, not sure why you'd put an imageview inside a webview) you can centre the image in its view and set the centre property of the imageview to be half the width of the webview bounds like this:

imageView.contentMode = UIViewContentModeCenter;
imageView.center = CGPointMake(webView.bounds.size.width/2, imageView.center.y).

If neither of those helps, try making your question clearer.

Upvotes: 2

Related Questions