I've got a very stubborn UIToolbar, who refuses to change its height no matter how may different methods I try.
I've seen this question and it does not work for me
Is there a way to change the height of a UIToolbar?
It is a toolbar for my cameraOverlayView while taking a picture. here is what I've tried and has not worked:
-Adjusting its current frame's height
-Creating a new CGRect for its frame
-Subclassing UIToolbar and editing its drawRect function
- (void)drawRect:(CGRect)rect
{
//Create a rectangle for the toolbar
CGRect rectArea = CGRectMake(0, 0, 320, 70);
[self setFrame:rectArea];
}
Is there some property I'm unaware of which prevents a UIToolbar from adjusting its height?
Just Follow How to change the height of UIToolbar
Related
So I'm building an iOS application, and I customized my UINavigationBar to be taller than the default size. A couple problems have arisen, however.
My content acts as if the UINavigationBar is of the default height. This results in any views at y=0 to actually be hidden, or partially hidden, by my taller UINavigationBar. I have to manually place views the correct offset downward, which isn't a terribly huge issue, but I'm curious as to whether anyone has found a way to fix this. Essentially my UINavigationBar is being treated as a normal one with a larger background image.
Any views/buttons in my UINavigationBar are not tappable if the portion being tapped is below the typical 44px bottom of a normal UINavigationBar. Anything within the normal range works fine, but below that 44px mark it doesn't register. Again, it's as if my UINavigationBar is being treated by the application as one with a normal height but a large background image. This is a much more critical issue that I really need to resolve.
Here is the code that modifies my UINavigationBar:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navBarBackground_iPhone.png"] forBarMetrics:UIBarMetricsDefault];
[self.navController.navigationBar setBackgroundColor:[UIColor whiteColor]];
[self.navController.navigationBar setFrame:CGRectMake(0, 0, self.frame.size.width, 72)];
This is performed in my main window's -makeKeyAndVisible after my UINavigationController is allocated and initialized with a root view controller. The background image is 320px wide and 72px tall (double for the #2x version).
As you can see, I attempt to set the UINavigationBar's height here, after this portion of code it doesn't seem to stick. It reverts to 44px.
I've tried unsuccessfully to subclass UINavigationBar. Any help is greatly appreciated.
Try to subclass UINavigationBar and override the following method:
- (void)drawRect:(CGRect)rect
{
int heightYouWant = 100;
UIImage *image = [UIImage imageNamed:#"title_bar_bg.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, heightYouWant)];
self.tintColor = [UIColor colorWithRed:1/255.0 green:62/255.0 blue:130/255.0 alpha:1];
}
Add this method to your subclass of UINavigationBar:
- (void)layoutSubviews {
[super layoutSubviews];
CGRect barFrame = self.frame;
barFrame.size.height = heightYouWant;
self.frame = barFrame;
}
I need a dynamically resizing UITextView but the right margin encroaches towards the left alarmingly after numerous resizes so that a very narrow strip of text is shown with lots of white space in the text view. This can be reproduced by a simple setup with just a UITextView and UISlider. A simple sample setup that produces this behavior is UISlider with value range from 0-200, a UITextView of 320 width and this code:
- (IBAction)sliderValueChanged:(UISlider *)slider {
textView.frame = CGRectMake(0, 0, 320 - slider.value, 300);
}
Some things I've tried are tinkering with the autoResizingMask, contentMode, contentOffset, and sizeToFit but none of them work. How can this weird behavior be avoided, or is it a bug?
Subclass UITextView and override layoutSubViews to set the frame to CGRectZero and then back to original frame size. It's not elegant but it works.
-(void) layoutSubviews
{
CGRect rect = [self frame];
[self setFrame:CGRectZero];
[self setFrame:rect];
}
I've UIViewController with navigation bar and scrollview within it.
When scrollview scrolls down I hide navigation bar and set bounds for scrollview to fit free space.
self.navigationController.navigationBarHidden = YES;
[scrollView setBounds:CGRectMake(0, 0, 320, 411)];
Height is 411 cos there is also UITabBarController.
But scrollview doesn't fit whole view. When I check it's frame it says that frame = (0 22; 320 411); How could I fix that?
I've tried to use setFrame function instead of setBounds. Also I dont need to resize it's content I need to change its frame.
i think you use setFrame and also setContentSize if needed here...
its may be happen because off its content size not manage after your scrollview bounds are changed...
hope this help you....
:)
I believe you need to set the frame of the scrollview.
scrollView.frame = CGRectMake(0, 0, 320, 411);
The bounds is a coordinate system in relation to the view and not its containing view.
Try to use setFrame function.
[scrollView setFrame:CGRectMake(0, 0, 320, 411)];
The above is what I get on the simulator regardless of the frame I set for the UITextView. The above UITextView is a subview to UIScrollView (the light gray view behind). And this UIScrollView has been presented modally. No matter what frame I set for the UITextView, its height remains as shown above. What could be the problem?
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 540, 620)];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, 520, 80)];
textView.contentInset = UIEdgeInsetsZero;
textView.layer.borderWidth = 1.0f;
textView.layer.borderColor = [[UIColor blackColor] CGColor];
[scrollView addSubview:textView];
Thanks!
Noted one more thing. Changing the width of the textview from say the above 520 to 220 does indeed result in a change of width and it shows. But no matter what the value of height is, the textview keeps displaying with the same height as in the above image.
your UITextView size is dependent on the Height and width of UIScrollView first increase the size of UIScrollView size than increase th eUITextView size.
I'm getting the same issue and when I try to po the frame height it give me:
property 'frame' not found on object of type 'UITextView *'
This is after installing the new ios6 dev kit... so maybe that's it...
Yup that's it. If you go to file inspector in your xib or storyboard and untick "use autolayout" then that will help.. But's it's screwed everything, so I'm just going to make the damned uitextview programatically!
I'm currently developing a simple text-editing app for iPad.
I want to set left/right margins like the attached picture.
Just adding UITextView into another UIView with larger width won't work because a scroll indicator won't be properly located.
Instead of UIView, I added UITextView into UIScrollView, and it works almost fine. But they sometimes show strange behaviors, and UITextViewDelegate doesn't work with my UIViewController.
Is there any way to set left/right margins only using UITextView?
Thank you.
You can use the property textContainerInset
Following the example of George Green:
myTextView.textContainerInset = UIEdgeInsetsMake(0.0f, 10.0f, 0.0f, 10.0f);
UITextView is a subclass of UIScrollView. I haven't tried it but you could try something like:
myTextView.contentInset = UIEdgeInsetsMake(0.0f, 10.0f, 0.0f, 10.0f);
UIEdgeInsetsMake() is as follows:
UIEdgeInsets UIEdgeInsetsMake (
CGFloat top,
CGFloat left,
CGFloat bottom,
CGFloat right
);
So you should be able to inset your textView content.
Hope this helps, let me know if it works!! :)
I wanted to do the same thing, but textview.contentInset didn't work.
I put UITextView with a narrow width on UIView, then move the scrollview indicator of textview to the right side, so I got what I wanted really well.
textView.clipsToBounds = NO;
textView.scrollIndicatorInsets = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, -20.0f);
This answer might help.
Is there a way to put UITextView's scroll indicator to outside UITextView?
You can set the scroller right inset value of the UITextView to negative value and disable the clip subview option to achieve your require. No other scrollview is needed.
In code it would be
textView.clipsToBounds = NO;
textView.scrollIndicatorInsets = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, -50.0f);