Advertise here




Advertise here

Howdy, Stranger!

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

get screen width

david_daviddavid_david Posts: 372Registered Users @ @
edited October 2008 in iOS SDK Development
hi

how can I get the screen width programmatically..?
I looked at the class NSScreen but I didn't find any methods. Hope you can help me..
Post edited by david_david on
<a href="http://davidbits.blogspot.com" target="_blank">lazy blogs</a><br />
The Lord's holy name be praised.
· ·

Replies

  • chbeerchbeer Posts: 229Registered Users
    edited October 2008
    NSScreen is the wrong class. As a rule: All classes for the UI start with UI.

    Simply use:
    [[UIScreen mainScreen] bounds]
    
    Learn vocabularies on iPhone? <a href="http://iphone.chbeer.de/iVocabulary" target="_blank">iVocabulary</a>!
    · ·
  • david_daviddavid_david Posts: 372Registered Users @ @
    edited October 2008
    thanks chbeer
    cheers !!
    <a href="http://davidbits.blogspot.com" target="_blank">lazy blogs</a><br />
    The Lord's holy name be praised.
    · ·
  • PhoneyDeveloperPhoneyDeveloper Posts: 1,431Registered Users
    edited October 2008
    Apparently the width and height reported by UIScreen bounds don't change when the device rotates so if your app can work rotated you may need to consider that.
    · ·
  • Stoff81Stoff81 Posts: 11Registered Users
    edited October 2008
    Hi, you may also want to verify that the screen dimensions take the staus bar into account (20 pixels). What i usually so is just store the dimensions manually...320 x 460 portrait and 480x300 in landscape. the nice thing about developing on iphone is that theres only one screen size. completely different story when developing apps for multiple devices :)
    · ·
  • CommanderDataCommanderData Posts: 486Registered Users
    edited October 2008
    Stoff81 wrote: »
    Hi, you may also want to verify that the screen dimensions take the staus bar into account (20 pixels). What i usually so is just store the dimensions manually...320 x 460 portrait and 480x300 in landscape. the nice thing about developing on iphone is that theres only one screen size. completely different story when developing apps for multiple devices :)

    I have done the same thing in a few apps, but I just know Apple's going to break that someday by bringing out a different sized or higher resolution device :D
    ChronoSoft - <a href="http://www.ChronoSoft.com" target="_blank">Rogue Touch</a> Available now in the <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=303471870&mt=8" target="_blank">App Store</a>! ... Version 1.5 available n
    · ·
  • Stoff81Stoff81 Posts: 11Registered Users
    edited October 2008
    true dat, i cant wait!!!
    · ·
  • RickMaddyRickMaddy Posts: 2,122New Users
    edited October 2008
    There are two properties in UIScreen that can be used here. No hard coding required.

    One gives the actual, physical screen size and the other gives the size used by your application - taking into account the status bar, if shown. Use the right method and get the right answer. Then you'll be one of the few apps that will work when the next device comes out ;)
    · ·
  • david_daviddavid_david Posts: 372Registered Users @ @
    edited October 2008
    Apparently the width and height reported by UIScreen bounds don't change when the device rotates so if your app can work rotated you may need to consider that.

    hi thanks for the information...
    CGRect cgRect =[[UIScreen mainScreen] bounds];
    CGSize cgSize = cgRect.size;
    txtmail = [[UITextField alloc] initWithFrame:CGRectMake(0, cgSize.height/2, cgSize.width, 30) ];
    

    it is ok when in portrait, but I rotate to landscape, the textfield is not fit with the width of the screen , and the y position is not changing accordingly.

    Is there any way to solve the bounds issue when device rotates..
    <a href="http://davidbits.blogspot.com" target="_blank">lazy blogs</a><br />
    The Lord's holy name be praised.
    · ·
  • PhoneyDeveloperPhoneyDeveloper Posts: 1,431Registered Users
    edited October 2008
    You have to set the autoresizingMask, probably to UIViewAutoresizingFlexibleWidth or maybe height also.
    · ·
  • david_daviddavid_david Posts: 372Registered Users @ @
    edited October 2008
    hi, let me know how to use this ...
    thanks in advance
    <a href="http://davidbits.blogspot.com" target="_blank">lazy blogs</a><br />
    The Lord's holy name be praised.
    · ·
  • PhoneyDeveloperPhoneyDeveloper Posts: 1,431Registered Users
    edited October 2008
    Um, OK. I usually do this in IB.
    txtmail.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
    

    You need to read the docs on this as it can be confusing. I find myself reading them every month or so to refresh my understanding. I think there's also a section on this in the IB manual, maybe referring to springs and struts.
    · ·
  • david_daviddavid_david Posts: 372Registered Users @ @
    edited October 2008
    much thanks for the info.
    (at first I searched that property for UITetField in Xcode documentation.I didn't find. Now understands it is inherited from UIView property right.)

    hope that I am not disturbing you..
    let me know one more thing, how can I auto adjust y value..
    suppose I want to keep the y position as screenheight/2.0 , but it not works when rotate..

    /* for documentation we are using in Xcode menu, Help->Documentation
    please inform any other docs or tutorial with samples*/
    <a href="http://davidbits.blogspot.com" target="_blank">lazy blogs</a><br />
    The Lord's holy name be praised.
    · ·
  • PhoneyDeveloperPhoneyDeveloper Posts: 1,431Registered Users
    edited October 2008
    To keep the view in the middle heightwise you need to set flexible top and bottom margin. I really suggest you look at the little animation in IB. It shows in a graphic way the effect of setting the various constants.
    · ·
  • david_daviddavid_david Posts: 372Registered Users @ @
    edited October 2008
    hi friend thanks for the information...
    //I need to do all programmatically. not with IB
    thanks for the help.
    cheers !!
    <a href="http://davidbits.blogspot.com" target="_blank">lazy blogs</a><br />
    The Lord's holy name be praised.
    · ·
Sign In or Register to comment.