Is it possible to set the height of a UIWebView by doing something like this..
[webView.height: currentHeight - 44px];
So essentially, I want to get the height of the UIWebView and then make it 44px shorter from the bottom, programmatically.
Save your old frame like this:
CGRect oldFrame = WebView.frame;
Then set the new frame :
CGRect newFrame =CGRectMake(oldFrame.origin.x, oldFrame.origin.y, oldFrame.size.width, oldFrame.size.height-44);
[WebView setFrame:newFrame];
Thats it :-)
I guess this should be enough.
webView.frame = CGRectMake(webView.frame.origin.x, webView.frame.origin.y, webView.frame.size.width, webView.frame.size.height - 44);
Related
I want to make a label that change its size depending on the size of the string value that it will show. Currently I am doing this:
[tfScroll setStringValue:strScoller];
[tfScroll sizeToFit];
However this is not working. What am I missing?
If your tfScroll is NSTextField:
CGRect frame = tfScroll.frame;
frame.size.width = tfScroll.attributedStringValue.size.width+somepoints;//(somepoints=8)
tfScroll.frame = frame;
I did not find NSTextfield.contentSize.
If you trying to resize the fields's height, this may works:
CGRect frame = tfScroll.frame;
frame.size.height = tfScroll.contentSize.height;
tfScroll.frame = frame;
I can get the UIPinchGestureRecognizer handler to work with scaling an object but I don't want to scale I want to change the size. For example I have a UIView and I've attacked a UIPinchGestureRecognizer gesture to it and if the user pinches I want to change the width of the UIView to match the pinch. I don't want to scale it so the UIView is larger(zooming)
If you have the UIPinchGestureRecognizer call a method pinch, you can do:
- (void) pinch:(UIPinchGestureRecognizer *)pinch
{
CGRect frame = [self.view frame];
frame.size.width = frame.size.width * pinch.scale;
[self.view setFrame:frame];
}
Here my dilemma. I have 4 elements inside a UIScrollView.
1. Top most element is a UILabel that I give height dynamically depending upon the amount of content in it.
2. Second is a fixed height UILabel that I give position dynamically depending upon the height given to the upper UILabel
3. Third element is a UIImageView that again I have to give position dynamically depending upon the height given to the topmost UILabel
4. The fourth is a UIWebView, to which I gave both, height & position dynamically. (Height depending upon the content in it.. and position again depending on the height of topmost UILabel)
Finally, I dynamically give height to my UIScrollView to accomodate all of the above elements.
Here is the code I use in - (void)webViewDidFinishLoad:(UIWebView *)webView to accomplish all of the above.
//Adjust height of top-most UILabel
CGSize maximumLabelSize = CGSizeMake(300,9999);
CGSize expectedLabelSize = [item.label1 sizeWithFont:label1.font constrainedToSize:maximumLabelSize lineBreakMode:label1.lineBreakMode];
CGRect newFrame = label1.frame;
newFrame.size.height = 0;
newFrame.size.height = expectedLabelSize.height;
label1.frame = newFrame;
//Adjust position of second UILlabel
CGRect labelPosition = label2.frame;
labelPosition.size.height = 20;
labelPosition.origin.y = expectedLabelSize.height +14;
label2.frame = labelPosition;
//Add UIImageView and adjust it's position
UIImageView *image;
image = [[UIImageView alloc] initWithFrame:CGRectMake(0, expectedLabelSize.height +41, 320, 2)];
image.image = [UIImage imageNamed:#"image.png"];
[scrollView addSubview:image];
[image release];
//Adjust UIWebView height and position
CGRect frame = webView.frame;
frame.size.height = 0;
frame.origin.y = expectedLabelSize.height +48;
webView.frame = frame;
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
webView.frame = frame;
//Adjust Scrollview height
scrollView.contentSize = CGSizeMake(320, fittingSize.height +expectedLabelSize.height +48);
Finally, my problem is that when I first load this view, everything but the scrollview get's proper height & position. But, if I go back one view & open this view again, the scrollview has the desired height.
Any ideas what I might be doing wrong here?
My guess is that the scrollView variable isn't yet initialized when this first runs. Try setting a breakpoint somewhere in this code and checking if scrollView has a value or if it's just 0x00000000.
I have a scrollview with an image as a subview. I would like to set the boundaries of the scrollview to be the size of the image view, so that you wouldn't be able to see any of the background.
I don't want this happening anymore.
The weird part is, that after you zoom in or out on the image, then the boundaries seem to fix themselves, and you can no longer move the image out of the way and see the background.
This is what I have going for code:
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView
{
// return which subview we want to zoom
return self.imageView;
}
-(void)viewDidLoad{
[super viewDidLoad];
[self sendLogMessage:#"Second View Controller Loaded"];
//sets the initial view to scale to fit the screen
self.imageView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
//sets the content size to be the size our our whole frame
self.scrollView.contentSize = self.imageView.image.size;
//setes the scrollview's delegate to itself
self.scrollView.delegate = self;
//sets the maximum zoom to 2.0, meaning that the picture can only become a maximum of twice as big
[self.scrollView setMaximumZoomScale : 2.5];
//sets the minimum zoom to 1.0 so that the scrollview can never be smaller than the image (no matter how far in/out we're zoomed)
[self.scrollView setMinimumZoomScale : 1.0];
[imageView addSubview:button];
}
I thought that this line would solve my problem
//sets the content size to be the size our our whole frame
self.scrollView.contentSize = self.imageView.image.size;
But like I said, it only works after I zoom in or out.
EDIT: When I switch
self.scrollView.contentSize = self.imageView.image.size;
to
self.scrollView.frame = self.imageView.frame;
It works like I want it to (you can't see the background), except the toolbar on the top is covered by the image.
imageView.image.size isn't necessarily the frame of the imageView itself, try setting the
scrollview.frame = imageView.frame
and then
scrollView.contentSize = imageView.image.size
Then you won't see any border. If you want the image to be the maximum size to start with,
do
imageView.frame = image.size;
[imageView setImage:image];
scrollView.frame = self.view.frame; //or desired size
[scrollView addSubView:imageView];
[scrollView setContentSize:image.size]; //or imageView.frame.size
To fix this, I ended up declaring a new CGRect , setting its origin to my scrollView's origin, setting its size with the bounds of my view, and then assigning this CGRect back to my scrollview frame
CGRect scrollFrame;
scrollFrame.origin = self.scrollView.frame.origin;
scrollFrame.size = CGSizeMake(CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
self.scrollView.frame = scrollFrame;
this window status bar.How to make the icon has been relying on the right ? Resize the window , it automatically to the right .
-(void)composeInterface{
NSView *themeFrame=[[self.window contentView] superview];
NSRect themeFrameRect = [themeFrame frame];
NSRect accessoryViewFrame =[self.statusBarBtn frame];
NSRect newFrame = NSMakeRect(30,
themeFrameRect.size.height - accessoryViewFrame.size.height,
accessoryViewFrame.size.width,
accessoryViewFrame.size.height);
[self.statusBarBtn setFrame:newFrame];
// [self.statusBarBtn setFrameOrigin:NSMakePoint(0, 0)];
// [self.statusBarBtn setAutoresizingMask:323];
[themeFrame addSubview:self.statusBarBtn];
}
If You want that Your icon will be aligned to the right You need to change it's Autosizing to align right. You need to do it like this in Size Inspector :
Or just use -setAutoresizingMask like this:
[self.statusBarBtn setAutoresizingMask:333]; //NOT 323
Furthermore Your newFrame's x possition is set to 30, so the icon will be in the left side.
Change this:
NSRect newFrame = NSMakeRect(30,
themeFrameRect.size.height - accessoryViewFrame.size.height,
accessoryViewFrame.size.width,
accessoryViewFrame.size.height);
To this:
NSRect newFrame = NSMakeRect(themeFrameRect.size.width - accessoryViewFrame.size.width,
themeFrameRect.size.height - accessoryViewFrame.size.height,
accessoryViewFrame.size.width,
accessoryViewFrame.size.height);