I am building an app that is presenting articles from a blog. I am using UICollectionView to present images that are parsed from the blog for each of the cells. This is my first go-round with a UICollectionView so I am wondering how you set up a background image of something like shelves that will scroll with the UICollectionView?
I have tried using:
self.collectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"shelves.jpg"]];
But this doesn't do anything.
What you're trying:
self.collectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"shelves.jpg"]];
should work. I do exactly this in viewDidLoad and it works for me. I would check that you're getting a valid image. Perhaps "shelves.jpg" needs to be added to the project?
You can just set the size of a UIImageView for your background to a size that is larger than the current UIView size then change the origin (increment) of that UIImageView based on your current visible cells for your UICollectionView. This would give you a side scrolling (parallax) effect based on which cells are currently being viewed.
There are other parallax effects people have created that you can get creative with to apply to your scenario. The idea is pretty simple.
Related
This is end end result I want:
And this is the thing I tried initially.
This does not work, the cells below/above the cell with the background will overlap or underlap the background depending on when they are added into the tableview (like via dequeue/scrolling).
I am quite OK with this not working, and I believe I can achieve it by other means. For example by adding these backgrounds as views within the tableview itself and moving them based on the content offset or similar ways, maybe adding a background image that is tall with them embedded.
But. I am curious if there are some easier way, just adding the view into the XIB and applying a rotation would be very nice.
The background should be below the text in the other cells as well - this is where the complications comes in.
Anyway. Is this possible in some super-neat way?
What you should do is setting all cell's background to clear, and to set a background to your UITableView or your UIView.
Or, as you suggest, you can add a UIView with a rotation applied, and add it as a subview of your UIView/UITableView, and send it to back with [self.view sendSubviewToBack:backgroundView].
I would like to draw rectangles in the background of the cells of a table view, whose size will indicate the progression of subsequent tasks:
The progression bar should take the whole height of the cell and its width will be programmatically set when the TableView is shown.
I would like to know how to get this result with a simple and efficient approach. I have not been able to find good practices for drawing a custom background for UITableViewCells, using CALayer or another solution.
Also, I would appreciate if the technical solution for this task could also be valid when deciding to animate the progression of the bars.
Thank you.
Simple solution without calculation is that, prepare a set of static different background images, and set them depend on the progress value.
Other solution requires you to create Progress view programmatically in table view's cellForRowAtIndex method and add to cell.contentView as subview
UIProgressView *progressView = [[UIProgressView alloc] init];
[progressView setFrame:cell.frame];
[cell.contentView insertSubview:progressView atIndex:0];
You can make progressview alpha property to 0.5 or some other value in order for your top views in cell.contentView to be visible properly
My UISearchController displays search results in UITableViewCells with background colour that I have not set
I can see by debugging the views that this grey colour is that of the cell.contentView. However, it doesn't react to me setting
cell.contentView.backgroundColor = [UIColor whiteColor];
in tableView:cellForRowAtIndexPath: method.
Are there any other methods to override that strange grey colour?
Are you able to provide an example project that reproduces your scenario? What does the tableView:cellForRowAtIndexPath: look like? If so, we can probably be much more helpful in determining the issue.
Without knowing specifics, it might be worth trying to set the contentView's backgroundColor in tableView:willDisplayCell:forRowAtIndexPath:, which occurs a bit later than tableView:cellForRowAtIndexPath:
It may also be worth making your own subclass of UITableViewCell so that you can better control the coloring of the cell.
I have a very specific requirement to fulfil.
Lets say this is my original background image (on the right).
This is how my image should be on the screen by default.
And this is how it should be when I do a "pull down" gesture on the UITableView.
I want to set an image (shown above) as a view's background. A UITableView to be specific.
NOTE: Image size is more than the view size.
When I try to pull down the view beyond the bounds of the view, the image should continue to show up and should not break. With the current implementation the image from the bottom part shows up.
Any ideas how I can achieve this? Pardon me if the solution is obvious.
You can do this by only one line of code
[yourView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"YourBGImgName.png"]]];
OR Alternately
put one UIScrollView and set it's background color with above way and you can find your background repeating when you scrolling your scrollView.
Set the top part as the background for a UITableViewHeaderFooterView in the header and do the same for the footer. Then set a negative inset for your tableView.
Something like
[self.tableView setContentInset:(UIEdgeInsets){-headerHeight, 0, -footerHeight, 0}];
I'm trying to reproduce the design of Twitter UITableView (see image below) :
Did not manage to reproduce it :(
I tried several methods like :
UITableViewController with self.view.layer.borderWidth = 3.0f + shadows + cornerRadius
UITableViewController with Grouped style and corner Radius
UIView with UITableView as a subview and corner radius
Any clue to solve my problem please ?
In advance, thanks a lot for your help.
In my opinion, this seems to be NOT your classic grouped style UITableView.
This could be a UITableView (plain style) that spans across the whole device width, and composed by custom UITableViewCell's. The cells are narrow enough to leave room for the scroll indicators to be shown.
Each UITableViewCell renders a UIImage on the cell's background: each different, depending on position - top, middle, bottom - or content type. The image for the cell background would already contain the shadow pixels. In an experience of mine, using Quartz for shadow, is too processor intensive and slow, iphone 4). In addition, each custom cell could also have its view setOpaque:TRUE for enhanced performance (against the solid colored background).
Each tweet cell may span different lines/heights so you'd probably use [UIColor colorWithPatternImage:[UIImage imageNamed:#"tile.png"]] when setting the background of the cell.
So we end up with no real shadow / processor intensive stuff. Just graphics, color matching and positioning.
This very similar to twitter UI
https://github.com/vicpenap/PrettyKit
I have used a simple trick wherein you use a UIView "Vbg" under UITableView and set the colour of cells and Table to clearcolor. Then increase the height:
Vbg.heightConstraint.constant = number of cells * height of cell.
I had to use this for fixed height cells , so this trick came up my mind and it worked pretty well.