UIImageView stretch...

Discussion in 'iOS Development' started by lolwut?, Apr 8, 2009.

  1. lolwut?

    lolwut? Banned

    Joined:
    Apr 5, 2009
    Messages:
    73
    Likes Received:
    0
    Device:
    iPod touch
    Well, I'm recreating the animation from when you tap the URL bar in Safari.
    It all works fine, except when I stretch the UIImageView for the URL bar, the image gets stretched beyond recognition. I've messed around with animationImages, but it's a bit much for something small like this, so I looked in Safari's images and found this:

    Please Register or Log in to view images



    How do they take this and make it into a full textfield-looking bar? :S
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Just use a regular UITextField.

    Code:
    yourTextField.borderStyle = UITextBorderStyleRoundedRect;

    Or, if you're asking about stretching an image while confusing the situation with this textfield nonsense, then just use something like this:

    Code:
    UIImage *aStretchedImage = [[UIImage imageNamed:@"anImagetoStretch.png"] stretchableImageWithLeftCapWidth:someNSInteger topCapHeight:someOtherNSInteger];


    EDIT: Once again I didn't read the opening post, only skimmed it. To answer your question, simply use a standard UITextField, set it to a roundedRect text field. then, when you need to animate it, use UIView animation. It's all fairly simple, and there are plenty of samples in this forum.
  3. lolwut?

    lolwut? Banned

    Joined:
    Apr 5, 2009
    Messages:
    73
    Likes Received:
    0
    Device:
    iPod touch
    Ah, thanks a ton.
    I needed that code, I couldn't use a UITextField and I was already using UIView animation

    Please Register or Log in to view images

    .
  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Why can't you use a UITextField? Anywhere you use a UIView (or subclass of), you can use a UITextField.
  5. lolwut?

    lolwut? Banned

    Joined:
    Apr 5, 2009
    Messages:
    73
    Likes Received:
    0
    Device:
    iPod touch
    The way I've set it up, I'm using a textfield with no background and a UIImageView.
    One of the reasons is that I needed the textfield to be smaller than 31px in height.
    ------------------double post merged------------------
    I'm having more trouble -.-

    For the animation, I'm using UIView beginAnimations, etc., and I change the text fields frame to be wider, and then when the animation starts, the text gets really compressed and then expands out as the text field gets bigger. It just doesn't look right.

    Also, I'm using your code, and when I make one UIImageView go back to its original size, it goes back to a really stretched image as its background and then it gets better as it goes back to the right length.

Share This Page