I have a UIView then I put small UIImageViews with an image but I would like to replace this with a UICollectionView. I am not sure how to make the cells go in a upside down U shape like this.
Any help would be appreciated.
This is what UICollectionView is for, however, this is an advanced subclass of UICollectionViewFlowLayout
and really not something to "ask" for a solution here on SO, however, Google and you will find some tutorials regarding custom layouts, for example.
If you have no dynamic updates or movement of the UIImageViews, and they will always be visible on the UI (not move out of the screen) you really don't need a UICollectionView for this, but rather a customized UIView with your custom UIImageViews on it.
You could do this in a XIB subclassed UIView and with AutoLayout for example. (You can still customize it to dynamically update and move of course if needed)
Sidenote:
If the UIImages loaded into the UIImageViews are big sized, they will soak your memory and you will probably run into memory problems, make sure your UIImage are thumbnails and according to the displayed UIView size.
Related
Is there any way to add a gradient to prototyped UITableViewCell in storyboard? To be specific, I want to allow users to add custom photos to the app and that photo will be displayed in the cell as a background. But there will be some labels above the image. So I want to add a gradient to the bottom of the cell to make labels always visible (regardless of background photo).
I know that this is possible programmatically, for example I may use CAGradientLayer like in this tutorial:
http://www.cocoawithlove.com/2009/08/adding-shadow-effects-to-uitableview.html
or this:
http://www.raywenderlich.com/32283/core-graphics-tutorial-lines-rectangles-and-gradients
But I am wondering if there is any way to do that just in storyboard.
Thanks.
As far as I know, there is no way to do this from interface builder.
Some things are just too complex to put a decent UI on it.
A neat little workaround would be to create an IBDesignable IBInspectable UIView subclass that programmatically does what you desire, than use that in your storyboary scene.
I have a screen in my app that pulls an unknown sized array from my user object, and must display an object for each item in the array that consists of a UIImageView for my background image, a UISwitch to activate/deactivate that particular item, a label with the name of the item, and a label that corresponds to the name of the item.
These are displayed in a UIScrollView, since there are nearly always going to be more items than will fit on the screen, especially on the iPhone 4.
I had initially quickly thrown together a static screen that consisted of 20 of these objects, but have found that I will often be exceeding that number of items in the array, and need to convert to a dynamic solution.
I have not used subclassing at all yet, and want to be sure that this is the proper solution before I dive into the implementation. Adding one subclass to my scrollView sounds a lot cleaner than adding each of those components individually and figuring out the spacing for various screens.
If this is the proper solution, are there any resources you could point me to to learn about how to properly do this subclassing? I.e., how to add a constructor for the objects where I can add the contents of the labels and state of the switch, and programmatically add constraints. I've only used constraints from the storyboard.
If you do not think that subclassing UIView would be the proper way to do this, what other solution would you suggest? I'm admittedly a novice when it comes to iOS development, so I apologize that this post seeks advice on where to start rather than help fixing a specific part of an implementation.
You should use UITableView or UICollectionView for that, and subclass UITableViewCell or UICollectionViewCell to create your custom view hierarchy.
UITableView and UICollectionView will handle reusing of cells which will help in memory management.
Update:
as you want to use UITableView so to add spacing between cells set number of sections to number of elements and then add header for section and set its height you can do that by implementing UITableViewDelegates visit below links for detail about UITableView and UITableViewDelegates
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/
I'm playing around with UICollectionView interactive transitions.
The very basic implementation is here.
Now I'm a bit stuck with Cells transitioning.
The idea is to change content of cells simultaneously with interactive layout transition.
Here is how it looks now.
The first layout
And the second layout
When transitioning is finished, I want to change content of cells on second layout.
1) Text label "Some label" should disappear from every cells
2) Text label "Another label" should appear on the right corner of each cell.
Key issue is I want this changes fade in/out according to UICollectionViewTransitionLayout.transitionProgress value during transitioning.
Something very similar implemented in Facebook Paper App.
Take look how content of cells is changing below (click on it).
Is anybody know an elegant way to replicate this effect?
This library will help you achieve what you are trying. If you are interested in custom animations I would suggest you use FB pop library
Well.
The solution is to subclass UICollectionViewCell.
Subclass should contain two UIView. One for big layout & one for small.
Initially UICollectionViewCell shows only small one.
Once we starting to update UICollectionViewTransitionLayout.transitionProgress for example from small to big we should do following steps:
Make an UIImage from big UIView
Put this image above small UIView
Set alpha of the image to 0
Continuously change alpha of UIImage to UICollectionViewTransitionLayout.transitionProgress value
Once transition is done just switch this to UIView
When you transitioning back you should switch big with small.
Done :-)
Perhaps it's something with Xcode 4.5+ or iOS 6 that makes my research fruitless so far, but...
Apple's own advice hasn't worked for me. I set the contentSize to something different, and it causes no changes.
I found this wasn't unique to me, but the answer in that question 1.) does not inform me about the problem and 2.) I'm left wondering if it's really impossible to create a simple, non-inheriting example of UIScrollView. Thus, this question.
A better answer's code was tried within viewDidLoad and viewDidAppear, but to no avail.
So what gives? Is it possible to create a simple, image-filled view that allows scrolling? Say... something as easy as this basic project I set up on github -- but working?
Create and initialize a UIScrollView
Add it as subview to the view of viewcontroller
Make an array of image names
In a loop create UIImageView and add the images and add imageviews into scrollview considering the width of images, set the frame of imageviews
Number of images is known and the width it consumes can be calulated from the loop itself use it to set the contentSize of the scrollview
I have a chat on a web site that looks like this.
I am now building an iPhone app for this and have some problems creating the same layout. I hope you can point me in the right direction. Is subviews or webviews the best choice?
If using UIView, UILabel and UIImage, what is the best way to make rounded corners and the little arrow. The gradient background should not scroll with the table view. What's the easiest way to calculate the hight of each message? What is the best way to async load the images over http?
If using a webview, what is the best way to populate it with data? Building string? Having a template and populate the image, username, time and message thru JavaScript? How can I resize the UITableCell and UIWebView to fit the contests?
Will a table full of UIWebView be much slower than using labels? Will I need to create it twice to return the height of the cell in heightForCellAtIndexPath and add it in cellForRowAtIndexPath?
Thanks for your help!
If you wish to see it live, visit www.aktieguiden.com
This is really a lot more than two questions, and I'll answer several of them.
I would use a table view with a resizable UIImage and a UITextView for each bubble. Use an image of the bubble in png with a transparent background, and make it resizable. Import it with UIImage's -(UIImage*)resizableImageWithCapInsets:(UIEdgeInsets)capInsets. To determine a height, UITextView has a contentSize property which will tell you the size of the view that can be scrolled. For asynchronous loading, use one of the many tutorials or frameworks for that purpose. Here is one:
http://developers.enormego.com/view/what_if_images_on_the_iphone_were_as_easy_as_html