Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

How to position many UIImage in a UIView with a specified space

morandsmorands Posts: 19Registered Users
edited December 2011 in iPhone SDK Development
Hi,
I have a quite complex question (at least for me): I have to handle some UIImage in a UIView but I want to put all those images at a determined distance between them (it's the shelf for a magazine app). Here is the code with the images:

self.cover = [[[UIImageView alloc] initWithFrame:CGRectMake(8, 70, 279, 410)] autorelease];
    _cover.backgroundColor=[UIColor clearColor];
    _cover.contentMode=UIViewContentModeScaleAspectFit;

I'd like to have those on 2 rows and much more ordinated.

fotokr.png How it looks now.

shelfz.png How it SHOULD look.

Here you can find the entire project, to edit it directly.

The guy who will help me fixing that will be listed in the thanks section of the app.

Thank you very much! :) :)
Post edited by morands on

Replies

  • DomeleDomele Posts: 2,990Registered Users @ @ @ @ @
    edited December 2011
    Define the spacing on the left and right, the spacing on the very top and bottom, and the space between two vertical images. Enumerate through your images, determine if the image number is odd or even. If odd, it's an image on the left. If it's even, it's an image on the right. For the x position, use totalWidth - spacing on the right - width of image. For every 2 images, you go through, add 1 to an int called row that initially starts at 1. For the y, multiply the row by the vertical spacing and then add the very top spacing.
    If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.<br />
    <br />
    New app - See screenshots and details at <a href="http://www.globaclock.com" target="_blank">www.globaclock.com</a>.<br />
    <br />
    If you want to
  • morandsmorands Posts: 19Registered Users
    edited December 2011
    Thanks for the reply but I haven't understood very well: what did you mean with
    For all the other images, determine if the image number is odd or even
    how can i determinate if an image is odd or even?!? Could you explain me what you mean in code, because I'm pretty new with obj-c? Thanks again!!! :)
  • DomeleDomele Posts: 2,990Registered Users @ @ @ @ @
    edited December 2011
    Well if your images are in an array, they have an index number. And now that I think about, you'd have to add 1 to index for my method to work. To check if this index number is odd or even you'd use %. The result will be the remainder of the division. So if x divided by 2 has a remainder, we know it's odd, if it doesn't, it's even.
    if (x % 2 == 0) {
    //x is even
    }
    else {
    //x is odd
    }
    
    If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.<br />
    <br />
    New app - See screenshots and details at <a href="http://www.globaclock.com" target="_blank">www.globaclock.com</a>.<br />
    <br />
    If you want to
  • morandsmorands Posts: 19Registered Users
    edited December 2011
    ah ok, but I'm not using an array: I have a .plist file on the web and in every item there's the url for the image to display, because in the final project the covers will be uploaded online every month. So the only code that I use is the one in the first post... I have never used an array, do I need to use one in this project? Thank you again :)
  • DomeleDomele Posts: 2,990Registered Users @ @ @ @ @
    edited December 2011
    Well the plist is probably an array so you just have to load it from memory. First you'll have to get the file path using NSBundle
    pathForResource:ofType:
    
    Then use NSArray's
    initWithContentsOfFile:
    
    method.
    If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.<br />
    <br />
    New app - See screenshots and details at <a href="http://www.globaclock.com" target="_blank">www.globaclock.com</a>.<br />
    <br />
    If you want to
  • morandsmorands Posts: 19Registered Users
    edited December 2011
    ok, I looked my plist a bit deeper and it's an array and every item is called "dict". but, to be honest, I haven't understood mostly of what you said: HOW and where to use the array's method? :confused: :confused:

    couldn't you take a look to my project I'm sure that it's very easy for you, but I'm new with all this stuff and I'm really lost!
  • DomeleDomele Posts: 2,990Registered Users @ @ @ @ @
    edited December 2011
    Sorry, but I'm not going to look at your project unless I'm getting paid. You'd probably create the array of images from your plist in viewDidLoad. But you'll have to implement lazy loading. Cocanetics has a UIImageView subclass for that: And Now Lazy Loading with NSURLConnection | Cocoanetics
    If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.<br />
    <br />
    New app - See screenshots and details at <a href="http://www.globaclock.com" target="_blank">www.globaclock.com</a>.<br />
    <br />
    If you want to
Sign In or Register to comment.