Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing UIView

I am trying to resize a UIView instance that is part of the tapjoy SDK.

here is the code:

- (UIView*)showFeaturedAppFullScreenAd:(NSString*)adURL withFrame:(CGRect)frame
{
    UIView *fullScreenAdView = nil;

    [self moveViewToFront];

    [self.view setAlpha:1];

    fullScreenAdView = [TJCFeaturedAppViewHandler showFullScreenAdWithURL:adURL withFrame:frame];
    [self.view addSubview:fullScreenAdView];

    return fullScreenAdView;
}

I tried adding my own setter method in the above method:

fullScreenAdView.frame = CGRectOffset(fullScreenAdView.frame, 50, 500);

But it had no effect on the tapjoy ad when I ran it.

My question is this: I am trying to resize this instance so that instead of taking up 100% of the device window, it takes up (let's say) 70%.

I have some ideas how to do this, but they're vague (such as writing fullScreenAdView = [mainScreen * 0.7f), but I was hoping someone would have some more concrete ideas.

edit: here's a super, high-tech picture of what my situation is. http://i207.photobucket.com/albums/bb289/teh_Mac/tjAd-1.jpg

This is the proto-method I have come up with so far:

fullScreenAdView.frame = CGRectMake(0,0, [mainScreen * 0.7f], [mainScreen * 0.7f];
like image 685
GPP Avatar asked Jan 09 '12 04:01

GPP


People also ask

How do I resize UIView by dragging from edges?

You can do this by checking the touch-start point. If it hits one of your four corners you can resize based on the distance between that touch-start point and the current-touch point. (If the touch-start point didn't hit a corner, we just move the view instead of resizing.)

What does sizeToFit do?

sizeToFit()Resizes the receiver's frame so that it's the minimum size needed to contain its cell.

What is swift sizeToFit?

sizeToFit()Resizes and moves the receiver view so it just encloses its subviews.


1 Answers

Why don't you use CGRectMake and make it a percentage of the superview?

float percentage = .7f;  //whatever you like
int xPosition = fullScreenAdView.superview.frame.size.width * ((1 - percentage) / 2);
int yPosition = fullScreenAdView.superview.frame.size.height * ((1 - percentage) / 2);

int width = fullScreenAdView.superview.frame.size.width * (1 - percentage);
int height = fullScreenAdView.superview.frame.size.height * (1 - percentage);

fullScreenAdView.frame = CGRectMake(xPosition, yPosition, width, height);

This is written off the top of my head, but I think with a little tweaking it would do what you want.

like image 75
JamesB41 Avatar answered Oct 02 '22 23:10

JamesB41