Tabular display of images - ios

I am very new in Iphone development.
I have a requirement to display images in a tabular form [row column wise].
---------------------------------------
| Img1 img2 img3 img4 |
| Img6 img7 img8 img9 |
---------------------------------------
Will you please inform me the best way to accomplish this.
Thanks in advance.
Suhas.

You can go for multi column grid table view layout , where you can define each and every row and column.
you can check this tutorial for Drawing a Grid in a iPhone UITableView – Tabular Cell Data
http://usxue.is-programmer.com/posts/14176.html
http://www.iphonedevx.com/?p=153

You should look into using a UIScrollView for this. Set the contentSize accordingly to your needs.

Related

Calculate number of items per row based on their width in SwiftUI

This is an extension of my previous question (Get width of a view using in SwiftUI)
I need to implement a layout where number of items per row is determined dynamically, based on their combined width (basically, place items in a row until they no longer fit).
I've been told that using the GeometryReader is a hacky way to do something in a declarative language, which is obviously true.
I have also been directed to this CollectionView-like component https://github.com/Q-Mobile/QGrid but the solution is static as the number of rows and cells per row is determined once, before any components are rendered.
I have no idea how to approach this, so any advice is very valuable for me!
❤️❤️❤️
TL;DR
GeometryReader may be a "hacky" solution, but it is the solution we have at the moment. It is possible to create a solution that reflows a small number of items dynamically, or a large number of items with a delay. My demo code would be unwieldy here, but it sounds like describing my approach may be useful.
Working with what we've got
Behind the scenes, SwiftUI is doing all kinds of optimized constraint solving to layout your views efficiently. In theory, reflowing content like you describe could be part of that constraint solving; in today's SwiftUI, it is not. Therefore, the only way to do what you are describing is some variant of the following:
Let SwiftUI lay everything out based on our data model.
Get the widths that SwiftUI decided on using Geometry reader and preferences/callbacks.
Use these widths to solve our reflow constraints.
Update the data model, which will trigger step 1.
Hopefully, this process converges to a stable layout, rather than entering an endless loop.
My results
After playing around with it, here's what I've gotten so far. You can see that a small number of items (29 in my example) reflow almost instantaneously as the width is changed. With a large number of items (262 in my example), there is a noticable delay. This shouldn't be much of an issue if the content and view width don't change and won't need to be updated frequently. The time is spent almost entirely in step 1, so until we get proper reflow support in SwiftUI, I suspect this is as good as it gets. (In case you're wondering, the vertical scrollview scrolls with normal responsiveness once the reflow is finished.)
My strategy
Essentially, my data model starts with a [String] array and transforms it to a [[String]] array, where each internal array corresponds to one line that will fit horizontally in my view. (Technically it starts with a String that is split on whitespace to form the [String], but in a generalized sense, I've got a collection I want to split into multiple lines.) Then I can lay it out using VStack, HStack, and ForEach.
My first approach was to try to read the widths off the actual views I'm displaying. However, I quickly ran into infinite recursions or weirdly unstable oscillations because it might truncate a Text view (e.g. [Four] [score] [and] [se...]), and then un-truncate once once the reflow changed, back and forth (or just end in a truncated state.
So I decided to cheat. I lay out all the words in a second, invisible horizontal scrollview. This way, they all get to take up as much space as they want, never get truncated, and most importantly, because this layout only depends on the [String] array and not the derived [[String]] array, it can never enter a recursive loop. You may think that laying each view twice (once for measuring width and once for displaying) is inefficient, but I found it to be dozens of times faster than trying to measure the widths from the displayed views, and to produce proper results 100% of the time.
+---------- FIRST TRY - CYCLIC ----------+ +-------- SECOND TRY - ACYCLIC --------+
| | | |
| +--------+ [String] +----------+ | | +-------+ [String] +--------+ |
| | | | | | | |
| | +--------------------------+ | | | v v |
| | | | | | | Hidden +--> Widths +--> [[String]] |
| v v + v | | layout | |
| Display +--> Widths +--> [[String]] | | v |
| layout | | Display |
| | | layout |
+----------------------------------------+ +--------------------------------------+
To read and save the widths, I adapted the GeometryReader/PreferenceKey approach detailed on swiftui-lab.com. The widths are saved in the view model, and updated whenever the number or size of views in the hidden scrollview change. Such a change (or changing the width of the view) then reflows the [String] array to [[String]] based on the widths saved in the model.
Summary
Now, whether any of this is useful in a shipping application will depend on how many items you want to reflow, and whether they will be static once laid out or changing often. But I found it to be a fascinating diversion!
It's a two step process using a GeometryReader.
Measure for each item the width of content(item).
Use measurements to lay items out into rows.
Only problem is that it has to recalculate on each redraw or cache the priorly measured width, which is not necessarily a problem with just a few items though.
I won't post the code here since it uses GeometryReader which is not something the author wants to use.

How to create a grid in WebGL with Babylon.js?

I am a newbie with babylon.js and webGL. I want to create a grid example 3 x 3 grid and place objects in the cells. Also, I always want to know in which cell the object is present if there is one.
Update :
I want to end up with a cube which has 3 rows 3 columns on each face. I can create a tiled plane for each face but I won't know what are the contents in each cell. Is there any way ?
Can someone guide me doing it ?
Thanks !!
So now that it's clearer - Babylon.js is just used to render this 3x3 grid.
The simplest way would be to create a grid item and store 1x1x1 boxes in it. this way it will look like a big cube, but will still consist of smaller items.
I have created a very simple playground demo to get you started - http://www.babylonjs-playground.com/#2CFAMI
This, of course, should be optimized and adjusted to your usecase, but this would be a simple way to create a 3x3x3 grid with boxes in different colors.
I hope it helps!

images padding when converting html to pdf using itextpdf and XMLWorker

I am using XMLWorker 5.5.3 and itextpdf 5.5.3 to convert html to pdf.
my html contain table with cells that conatin images.
i.e. part of my code :
my problem is that some cells add padding > 0 so the td that contain the image is bigger than it should be.
Is there a way to define style for images so the will not have padding and margin ?
I am looking at css Demo of Itextpdf and not finding a solution , any help/trick /ideas will help .
thanks
Tami
I found a solution:
when I create the table I define columns width :
PdfPTable table = new PdfPTable(vColWidth.length);
table.setWidthPercentage(100);
table.setWidths(vColWidth);
when creating the Image object I define :
RegularImg = Image.getInstance(imgsrc);
RegularImg.setSpacingAfter(0);
RegularImg.setSpacingBefore(0);
when defining the td :
cell = new PdfPCell(RegularImg);
if(colSpan!="")
cell.setColspan(Integer.parseInt(colSpan));
if(rowSpan!= "")
cell.setRowspan(Integer.parseInt(rowSpan));
if(cellHight!="")
cell.setFixedHeight(Float.parseFloat(cellHight));
table.addCell(cell);
this solutions works o.k. if the table is not so big or complicated with the colSpan , rowSpan .
In complicated cases I advise people to convert the table of pictures as a Canvas , not using a table. just place each Image in the specific place in the doc . (the performance are much faster.

UIImage smart resizing

I have problem with making resizable UIImage where corners are not resized. What I want to achieve is to resize middle part using UIImageResizingModeTile. I.e. it should look something like following figure where corners A, B, C, D are original and all other parts are resized:
|-------------|
|A| |B|
|-------------|
| |
| |
|-------------|
|C| |D|
|-------------|
I tried with resizableImageWithCapInsets: but it doesn't resize middle parts well in way they are not made as pattern, but instead then are stretched which looks pretty bad. I noticed that because my image has "bubble" border so it's pretty noticeable. Take a look at sample image, it may be helpful.

how to give horizontal paging in blackberry

-Display the first 3 images in 3 views on the Screen that are visible to the user (e.g. <-- img1 img2 img3 -->)
-Keep a record of what's on display..
-When a user scrolls left or right the next/previous image in the array is displayed.
E.g scrolling right once will give me ( <-- img4 img5 img6 --> )
and so on...and also img click events
Since API 5.0 there is PictureScrollField which looks like does what you need. On a pre 5.0 OS you'll have to code your own custom component.

Resources