I need a NavigationBar like in the calendar in iOS 7.
I have noticed that the NavigationBar does not have any blur behind it.
when going back from one detail view. It's just the "main" NavigationBar that is "normal".
Anyone have any idea how to do this?
I have tried to do this:
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, 320, 88)];
But this would move the title and the buttons down 44px.
I have another idea to add another navigation bar under the navigationController.navigationBar, but then I have a line under the first navigation bar. Anyone knows how to remove this?
Thanks!
I fixed it!
I placed a other NavigationBar under the "main" NavigationBar. Removed the "main" NavigationBars shadow line.
Remove the NavigationBar translucent and set the background color to 97% white. (it's standard). If translucent is YES it would look strange when content is behind .
[self.navigationController.navigationBar setTranslucent:NO];
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithWhite:0.97 alpha:1]];
[NavigationBarExtension setTranslucent:NO];
[NavigationBarExtension setBarTintColor:[UIColor colorWithWhite:0.97 alpha:1]];
Code to remove the line (do this in viewWillAppear: because if you push a other view controller the line must come back)
- (void)viewWillAppear:(BOOL)animated {
for (UIView *view in self.navigationController.navigationBar.subviews) {
if ([view isKindOfClass:NSClassFromString(#"_UINavigationBarBackground")]) {
for (UIView *view2 in view.subviews) {
if ([view2 isKindOfClass:[UIImageView class]] && view2.frame.size.height < 1) {
[view2 setHidden:YES];
break;
}
}
}
}
}
Code to show the line when pushing a other view controller:
- (void)viewWillAppear:(BOOL)animated {
for (UIView *view in self.navigationController.navigationBar.subviews) {
if ([view isKindOfClass:NSClassFromString(#"_UINavigationBarBackground")]) {
for (UIView *view2 in view.subviews) {
if ([view2 isKindOfClass:[UIImageView class]] && view2.frame.size.height < 1) {
[view2 setHidden:NO];
break;
}
}
}
}
}
Related
With iOS 11 navigation bar's title view and bar button item is not centered.
Also the background image's height does not change and is not shown in full.The bar height is 74.
See the white space.
I have tried this
if(#available(iOS 11,*)){
_homeNavigationBar.prefersLargeTitles = NO;
_homeNavigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeNever;
[_homeNavigationBar setBarTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"navbarBg.png"]]];
}
else{
[_homeNavigationBar setBackgroundImage:[UIImage imageNamed:#"navbarBg.png"] forBarMetrics:UIBarMetricsDefault];
}
But still i am unable to center the title and bar button item.
Any idea how can i fix this?Please do let me know.Thanks
Subclassing the navigation bar did the trick for me.
- (void)layoutSubviews {
[super layoutSubviews];
for (UIView *view in self.subviews) {
if([NSStringFromClass([view class]) containsString:#"Background"]) {
view.frame = self.bounds;
}
else if ([NSStringFromClass([view class]) containsString:#"ContentView"]) {
CGRect frame = view.frame;
frame.origin.y = 25;
view.frame = frame;
}
}
}
I'm trying to make a UISearchBar rectangular instead of rounded, but all the solutions I found so far (mostly iterating through subviews) seem broken on iOS 7.
I did some research myself and as it turns out, it only has a UIView subview, which has additional subviews, a UISearchBarBackground and a UISearchBarTextField (both of them are private classes).
I tried
if ([view isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[view removeFromSuperview];
}
and
if ([view conformsToProtocol:#protocol(UITextInputTraits)]) {
#try {
[(UITextField *)view setBorderStyle:UITextBorderStyleRoundedRect];
}
#catch (NSException * e) {
// ignore exception
}
}
where view is the subview of that one UIView subview but none of them seems to work.
Try this... (I know it is also using subview but it is working in ios7)
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 20, 320, 49)];
[self.view addSubview:searchBar];
[self checkSubViewsOfView:searchBar WithTabIndex:#""];
and Add this method
-(void)checkSubViewsOfView:(UIView *)view WithTabIndex:(NSString *)strTab
{
if ([view isKindOfClass:NSClassFromString(#"UISearchBarTextField")])
{
view.layer.borderWidth = 1;
view.layer.borderColor = [[UIColor whiteColor] CGColor];
return;
}
for (UIView *vvv in view.subviews)
{
NSLog(#"%#%#",strTab,[vvv description]);
if (vvv.subviews > 0)
{
NSString *str = [NSString stringWithFormat:#"____%#",strTab];
[self checkSubViewsOfView:vvv WithTabIndex:str];
}
}
}
you can set the searchfield-background like this:
[self.searchBar setSearchFieldBackgroundImage:[[UIImage imageNamed:#"searchbar_stretch-0-10-0-10"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)] forState:UIControlStateNormal];
and the searchbar-background like this:
[self.searchBar setBackgroundImage:[UIImage imageNamed:#"categories_navbar"]];
I am using custom navigationBar within my projects, but it's giving bottom drop shadow of UINavigation bar, How we can remove it, Please provide the answer for it if any work on it.
TIA :)
The easiest way to remove the shadow underneath the UINavigationBar is to set a custom background image and then set the shadow image to a blank UIImage.
CustomViewController.m
- (void)viewDidLoad
{
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"Background"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
In the above example, "Background" would be a PNG image in your project.
in iOS7:
for (UIView *view in self.navigationController.navigationBar.subviews) {
for (UIView *view2 in view.subviews) {
if ([view2 isKindOfClass:[UIImageView class]]) {
if (view2.frame.size.height < 1) {
[view2 removeFromSuperview];
}
}
}
}
I am adding a view to the navigation bar
UIView *mySubView = [UIView alloc] initwithFrame:frame];
[self.navigationController.navigationBar addSubview:mySubView];
I want to remove the view before pushing to secondviewController.
[mySubView removeFromSuperView];
When App launch first time it did not remove the view, so view also visible on secondview navigation bar
I searched and tried many approaches, but didn't find any solution.
Assign a tag to you mysubview like
UIView *mySubView = [UIView alloc] initwithFrame:frame];
mySubView.tag =1;
[self.navigationController.navigationBar addSubview:mySubView];
Then add this line when you push to secondViewController.
[[self.navigationController.navigationBar viewWithTag:1] removeFromSuperview];
Hope it helps you.
Add a value to the tag property of the views you want to remove and check for it before removing the the subview, for example, assuming that you add a non-zero value to your subviews:
for (UIView *view in self.navigationController.navigationBar.subviews) {
if (view.tag != 0) {
[view removeFromSuperview];
}
}
Try this it will help !!!!
Do following for the ViewController in which you are having subView for NavigationBar
in .h
#property (nonatomic, retain) UIView *mySubView;
in .m
- (void)viewDidLoad {
//Your Existing Code + following 2 lines
self.mySubView = [[UIView alloc] initWithFrame:yourFrame];
self.mySubView.backgroundColor = [UIColor whiteColor];
}
- (void)viewWillAppear:(BOOL)animated {
//Your Existing Code + following 1 line
[self.navigationController.navigationBar addSubview:self.mySubView];
}
- (void)viewWillDisappear:(BOOL)animated {
//Your Existing Code + following 1 line
[self.mySubView removeFromSuperview];
}
And you are good to go. Tried and tested.
-(void)viewWillDisappear:(BOOL)animated
{
[self.mySubView removeFromSuperview];
//[_mySubView removeFromSuperview];
}
How do remove the gradient from a UIWebView - the one that you see if you overscroll the top or bottom.
This code
webView.backgroundColor = [UIColor whiteColor];
just changes the color of the gradient, it doesn't removes it. How can this be done?
(note: not the same question as UIWebView underside)
Aha, yes terminology fail. I wouldn't call that a shadow at all, but c'est la vie. Here is my type-safe code to achieve the effect. To summarise: this will hide any image-view children of the scroll view. It's not as vulnerable to change as the (objectAtIndex:0) methods, so if Apple re-order the children of the webView control it will work fine, but still relies on the fact that the gradient effect is applied by imageviews parented to the scroll view (and that there is indeed a scrollview underpinning the web view).
{
webView.backgroundColor = [UIColor whiteColor];
for (UIView* subView in [webView subviews])
{
if ([subView isKindOfClass:[UIScrollView class]]) {
for (UIView* shadowView in [subView subviews])
{
if ([shadowView isKindOfClass:[UIImageView class]]) {
[shadowView setHidden:YES];
}
}
}
}
}
To transparent the UIWebView and remove the scrolls.
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
for(UIView *view in webView.subviews){
if ([view isKindOfClass:[UIImageView class]]) {
// to transparent
[view removeFromSuperview];
}
if ([view isKindOfClass:[UIScrollView class]]) {
UIScrollView *sView = (UIScrollView *)view;
for (UIView* shadowView in [sView subviews]){
//to remove shadow
if ([shadowView isKindOfClass:[UIImageView class]]) {
[shadowView setHidden:YES];
}
}
}
}
for hide scroll indicators
You mean the shadow? Remove UIWebView Shadow?
The only way I found how to do this was :
for(UIView *aView in [[[webView subviews] objectAtIndex:0] subviews]) {
if([aView isKindOfClass:[UIImageView class]]) { aView.hidden = YES; }
}
It just just steps thru the subviews of UIWebView and removes the view if it is an image view.
I haven't put this in any App Store apps, so I don't know if Apple would accept it.
EDIT: Brian's link provides more details.
Using method suggested above you won't be able to edit your scroll indicator/insets later. They appear as UIImageView also, so you should check for last object:
UIView* lastView = [[subView subviews] lastObject];
for (UIView* shadowView in [subView subviews])
{
if(shadowView!=lastView) ... <-this one is a scroll
}
I was able to do this by adding white subviews to the top and bottom of the WebView’s scrollView. I control the content of the WebView, so I know that white is OK - this won’t work if you are loading arbitrary content.
// _topCover and _bottomCover are ivar UIViews
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// with cover views 300pt high, I couldn't scroll far enough to see the shadow,
// even in portrait on an iPad, which gives you the longest scroll distance
CGFloat coverage = 300;
_topCover = [[UIView alloc] initWithFrame:CGRectMake(0, -coverage, webView.bounds.size.width, coverage)];
_bottomCover = [[UIView alloc] initWithFrame:CGRectMake(0, webView.scrollView.contentSize.height, webView.bounds.size.width, coverage)];
_topCover.backgroundColor = [UIColor whiteColor];
_bottomCover.backgroundColor = [UIColor whiteColor];
// in case the webView is resized, e.g. by rotating the device
_topCover.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
_bottomCover.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
[webView.scrollView addSubview:_topCover];
[webView.scrollView addSubview:_bottomCover];
}
I run it it after the page loads so that webView.scrollView.contentSize.height will give me the correct height. I’m not sure how this will work if your pages are dynamically changing height. My page loads only once; if yours is reloading, you will want to skip running alloc/init on _topCover and _bottomCover after the first time for efficiency.
Update: I’m not sure that my use of autoresizingMask, above, is sufficient when the view rotates. You may need to put this in the UIViewController that contains your UIWebView to resize the covers after rotating:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
CGFloat coverage = 300;
_topCover.frame = CGRectMake(0, -coverage, self.webView.bounds.size.width, coverage);
_bottomCover.frame = CGRectMake(0, self.webView.scrollView.contentSize.height, self.webView.bounds.size.width, coverage);
}
I've built upon #damithH 's answer
#implementation UIWebView (Extensions)
- (void)setBackgroundAndShadowVisible:(BOOL)visible
{
self.opaque = !visible;
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:visible ? 1.0 : 0.0];
for(UIView *view in [self subviews])
{
if([view isKindOfClass:[UIImageView class]])
{
view.hidden = !visible;
}
if([view isKindOfClass:[UIScrollView class]])
{
UIScrollView *scrollView = (UIScrollView *)view;
for (UIView *shadowView in [scrollView subviews])
{
if ([shadowView isKindOfClass:[UIImageView class]])
{
shadowView.hidden = !visible;
}
}
}
}
}
#end
if (UIDevice.currentDevice.systemVersion.intValue < 7)
for (UIImageView *imageView in webView.scrollView.subviews)
if ([imageView isKindOfClass:[UIImageView class]] && imageView.image.size.width == 1)
imageView.hidden = YES;