How to add shadow to uicollection view ? ios - ios

I need to add a bottom shadow my collection view,here is my code:
weakself!.layer.shadowPath = UIBezierPath(rect: weakself!.bounds).CGPath
weakself!.layer.masksToBounds = false
weakself!.layer.shadowOffset = CGSizeMake(0.0, 3.0);
weakself!.layer.shadowColor = UIColor.blackColor().CGColor
weakself!.layer.shadowOpacity = 0.5
the above code is work perfect with other views. but it make the collection view to scroll above it's bounds. as you can see here in the bellow picture where the collection view scroll above the search bar:

If you need to do this you should add the collection view to a plain view, don't change the collection view, add the shadow to the plain view (the collections views superview).
I'd really recommend not using a shadow but instead presenting the collection as a popover or at least with a full screen backing view which dimmed the background and made the collection view more obvious (and prevented taps on other things like the partially visible buttons).

you are using swift.But I'm well in objective c.so the concept is same.then try this.
self.youView.layer.shadowColor = [[UIColor blackColor] CGColor];
self.youView.layer.shadowOffset = CGSizeMake(1, 1);
self.youView.layer.shadowOpacity = 1;
self.youView.layer.shadowRadius = 1.0;

Related

Add "shadow" to view

I have cells with 2 "rectangles". What i want is, add shadow to right rectangle. It will be better explained on screenshot:
From left is first part of cell (first rectangle) and on a right in second part. I want to add a shadow that look like on a screenshot. I tried:
-(void)addInnerShadow{
self.bgDetailsView.layer.shadowColor = [UIColor colorWithHexString:#"#a4c2e0"].CGColor;
self.bgDetailsView.layer.shadowOffset = (CGSize){SHADOW_SIDE_HEIGHT,0};
// self.vSelectionBack.layer.shadowRadius = 1.4;
self.bgDetailsView.layer.shadowRadius = SHADOW_SIDE_HEIGHT;
self.bgDetailsView.layer.shadowOpacity = .5;
}
Where bgDetailsView is second (right) view, but it has no effect.
Ok, so as I understand you want to add shadow to right view and shadow casts over the left view.
To do so:
You can set self.bgDetailsView.clipsToBounds = NO, it will make shadow visible but will also make your shadow to be visible over and below the right view.
You can put right view in container. Set clipsToBounds = NO in right view and make container view a bit bigger to the left.
You can also make a container view with additional CALayer or UIImageView with shadow image. Put your right view to right of this additional view/layer and set in container clipsToBounds = NO.
You can also use shadowPath property of right view layer and put it in container view:
self.bgDetailsView.layer.shadowPath = [UIBezierPath bezierPathWithRect:shadowRect].CGPath;

How to set this Detail View Alpha 1.0 , non transparent in ios?

When I click on Share button. Open Share_view. and its alpha 0.5 but I am add another view on Share view.
But I want to this view alpha 1.0 and its not transparent I want to see full white.
See my Image
I had try this, but this is not working at all:
[Detail_view setBackgroundColor:[[UIColor White] colorWithAlphaComponent:1.0]];
As far as I understand, you are adding Detail_view on Share_view, hence Share_view is the parent for your Detail_view.
Solution -
Make Detail_view a subview of self.view, i.e
[self.view addSubview:Detail_view];
If you want Detail_view on Share_view, you can do this:
Don't set the alpha directly on the parent view. Instead use
[Share_view setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5]];
Now any child view can have its own color and will NOT be transparent.

Xamarin iOS Table View Cells Intersecting Search Bar

I'm writing an iOS app using Xamarin and am having a problem with a table view and search bar - when the search bar has been clicked and text entered, the search results view controller doesn't work properly - the cells, when scrolled, intersect the search bar.
For clarity, I've recorded the problem:
YouTube - iOS Problem
So far, I've worked-out that the problem isn't related to the number of sections, the section header, or the table header. Completely out of ideas now, though...
The following can be used as an example, as the same problem appears there:
GitHub - TableSearch
In this example, adding the following line of code to the end of the 'ViewDidLoad ()' method within the 'MainTableViewController.cs' file will make the problem more obvious:
searchController.SearchBar.SearchBarStyle = UISearchBarStyle.Minimal;
EDIT
Looking at the image below, I ideally need to remove or shrink the top region (what seems to be a space for the iOS navigation bar):
Have you had a look at the sample from Xamarin here which has the same layout you are using, just to compare how you set up the search bar.
EDIT
I now see what you mean, I think this is a bug in iOS as the background color is transparent on the search bar and you would never want that.
I just added another view to cover up the status bar and set the background color to white:
searchController.SearchBar.SearchBarStyle = UISearchBarStyle.Minimal;
searchController.SearchBar.BackgroundColor = UIColor.White;
var frame = searchController.SearchBar.Frame;
frame.Height = searchController.SearchBar.Frame.Height + 22;
frame.Y = searchController.SearchBar.Frame.Y - 22;
var bckGRound = new UIView (frame);
bckGRound.BackgroundColor = UIColor.White;
searchController.SearchBar.InsertSubview (bckGRound, 0);
UPDATE
I realised that for your scenario you can't just add a view to cover this up so i was looking into adding blurring to searchbar like so:
var frame = searchController.SearchBar.Frame;
frame.Height = searchController.SearchBar.Frame.Height + 44;
frame.Y = searchController.SearchBar.Frame.Y - 22;
var blurryBackGround = new UIView (frame);
if (!UIAccessibility.IsReduceTransparencyEnabled)
{
blurryBackGround.BackgroundColor = UIColor.Clear;
var blureffect = UIBlurEffect.FromStyle (UIBlurEffectStyle.Light);
var blureffectview = new UIVisualEffectView (blureffect);
blureffectview.Frame = frame;
blurryBackGround.AddSubview (blureffectview);
}
else
{
blurryBackGround.BackgroundColor = UIColor.Black;
}
searchController.SearchBar.InsertSubview (blurryBackGround, 0);
UPDATE 2
If your background doesnt move with the table then you might be able to get away with just cropping the background image section that the search bar covers then set the backgroundimage for the search bar with this code:
searchController.SearchBar.SetBackgroundImage (new UIImage ("image.jpg"), UIBarPosition.TopAttached, UIBarMetrics.Default);
That is the UISearchController's default behavior. You can change the background color so that the rows don't appear behind the searchBar but that doesn't appear to be the behavior you want. Another option is to implement the UISearchBar on your ViewController which is what I have and it does scroll with the rows which is the behavior you are looking for. Hope this helps.
See: https://github.com/xamarin/monotouch-samples/tree/master/SearchDemo/SearchDemo

After changes on a storyboard ViewController, the elements modified still takes old values

I have make some updates from my storyboard on differents objects inside a ViewController.
Also, I have a method which customize my UITextFields with shadow, rounded corners etc :
-(void)createShadowBordersToView:(UIView *) view{
UIView * whiteRoundedCornerView;
whiteRoundedCornerView = [[UIView alloc] initWithFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height)];
whiteRoundedCornerView.backgroundColor = [UIColor whiteColor];
whiteRoundedCornerView.layer.masksToBounds = NO;
whiteRoundedCornerView.layer.cornerRadius = 3.0;
whiteRoundedCornerView.layer.shadowOffset = CGSizeMake(2, 2);
whiteRoundedCornerView.layer.shadowOpacity = 0.5;
whiteRoundedCornerView.layer.shadowColor = [[UIColor lightGrayColor]CGColor];
[self.container insertSubview:whiteRoundedCornerView belowSubview:view];
}
as you can see I put an UIView under my textfield with some style to create the illusion that the textfield is customized. I create this view with the origin and the size of the UITextView passed in parameter.
However, since I've updated the position and the width of my UITextFields from storyboard, this method always init a UIView with the old positions and width (my frames are well updated from my storyboard and I have no warnings).
So now, I have all my UITextFields with the right position and the right size, but their background views are still at the old position and they have old size (before my updates).
My view controller from my story board :
My results :
Well it was a bad idea to create an UIView to customize my textfields, I manage directly the layer of my textfields and now everything work fine.

ios uitableview bounce went wrong

I implemented a horizontal table view and it looks like this
The category bar, Dining Shopping something, is a horizontal table view and here is the implementation code.
LogInfo(#"Show Category Table start");
// add categories to be subview controller
self.categoriesTable = [[UITableView alloc] init];
self.categoriesTable.transform = CGAffineTransformMakeRotation(-M_PI * 0.5);
[self.categoriesTable setFrame:CGRectMake(0, 64, SCREENWIDTH, 44)];
self.categoriesTable.showsVerticalScrollIndicator = NO;
self.categoriesTable.showsHorizontalScrollIndicator = NO;
self.categoriesTable.pagingEnabled = YES;
self.categoriesTable.delegate = self;
self.categoriesTable.dataSource = self;
self.categoriesTable.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.superView addSubview:self.categoriesTable];
LogInfo(#"Show Category Table Finished");
self.categoriesTable.backgroundColor= [UIColor redColor];
It works as expect but if I change view, for example, I click any button to go to other view and go back to this view. The tableview looks like this
This problem also happpens even if I disable the bounce effect of the table view. Does anyone know how to solve this problem? Thanks!
Rather than applying a transform to the table to make it horizontal, use a collectionView with a horizontal layout.
Edit: If you want to continue using your current setup, try disabling automaticallyAdjustsScrollViewInsets on your view controller.
self.automaticallyAdjustsScrollViewInsets = NO
Edit 2: If you're curious, since iOS 7 every view controller looks at its topmost/first scroll view and adjusts its contentInsets to compensate for the navigation bar transparency which is enabled by default. In this case of course, such behaviour isn't desired at all.

Resources