How can remove the bottom shadow of UINavigationBar? - uinavigationbar

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];
}
}
}
}

Related

Change color of circular edit button in UITableViewCell

How can I change the image for the delete button in a table view cell?
I mean the red circle button on the left side:
Override the following in your UITableViewCell subclass:
- (void)willTransitionToState:(UITableViewCellStateMask)state
{
[super willTransitionToState:state];
if(state == UITableViewCellStateShowingEditControlMask)
{
for (UIView *v in self.subviews) {
if ([NSStringFromClass([v class]) isEqualToString:#"UITableViewCellEditControl"]) {
UIImageView *customButton = [[UIImageView alloc]initWithFrame:v.bounds];
[customButton setImage:[UIImage imageNamed:#"delete.png"]];
[v addSubview:customButton];
[v bringSubviewToFront:customButton];
}
}
}
}
You can play with the subviews and the states to achieve your preferred result.

UISegmentedControl tintColor

I'm having problems getting UISegmentedControl to show the desired tint color.
// AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// need red tint color in other views of the app
[[UIView appearance] setTintColor:[UIColor redColor]];
return YES;
}
// ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *items = #[#"Item 1", #"Item 2"];
UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:items];
// would like to have this control to have a green tint color
control.tintColor = [UIColor greenColor];
[self.view addSubview:control];
}
How to make UISegmentedControl use the green tint color?
I ended up creating a category for the desired behaviour. Subview structure looks like this:
UISegment
UISegmentLabel
UIImageView
UISegment
UISegmentLabel
UIImageView
So two loops are required for the desired effect (otherwise some parts stay in old tint color).
UISegmentedControl+TintColor.h
#import <UIKit/UIKit.h>
#interface UISegmentedControl (TintColor)
#end
UISegmentedControl+TintColor.m
#import "UISegmentedControl+TintColor.h"
#implementation UISegmentedControl (TintColor)
- (void)setTintColor:(UIColor *)tintColor {
[super setTintColor:tintColor];
for (UIView *subview in self.subviews) {
subview.tintColor = tintColor;
for (UIView *subsubview in subview.subviews) {
subsubview.tintColor = tintColor;
}
}
}
#end
Try something like this ?
for (UIView *subView in mySegmentedControl.subviews)
{
[subView setTintColor: [UIColor greenColor]];
}
But it actually appears that it is a known issue in iOS 7, I don't know if it has been fixed in iOS 8.
"You cannot customize the segmented control’s style on iOS 7. Segmented controls only have one style"
UIKit User Interface Catalog

Set UINavigationBar height like in iOS 7 calendar app

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;
}
}
}
}
}

iOS navigation bar subview reappear after removing

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];
}

Remove gradient background from UIWebView?

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;

Resources