Lazy loading issue in UITableView - iphone

I have implemented lazy loading in my UITableView,
in which, i am downloading images from server, and server contains images with different sizes..
and displays like this,
:
Images getting displayed properly but the problem is UITableViewCell Text is not getting displayed properly align in single line as you can see in the image alignment of UITableViewCell Text is not in the single line
Means:Cell 0 to Cell 4 is displayed properly because server contains images with size of 100*100 for Cell 0 to Cell 4 but alignment of cell 5 and cell 6 is different because server contains image with different size of 85*85
Is there any way in which i can set Text alignment in single line ??
Thanks in advance.

i Suggest you to use Custom table-cell with One image-view and Label and set Imageview contentMode like bellow
imageView.contentMode = UIViewContentModeScaleAspectFill; //will fill the frame
imageView.contentMode = UIViewContentModeScaleAspectFit; //will show the entire image, possibly leaving areas of the frame open.
and your Label set Number of Line 0

I think Custom TableView Cell will do for you.
You can design a cell like below
https://www.dropbox.com/s/r9r6dsmdwmpk50h/customcell.png

You can use
imageView.contentMode = UIViewContentModeScaleAspectFit;
to adjust the imagview width and height based on image size

Related

UIImage size depending on UITableViewCell height

I have a UITableView whose cells have dynamic height. What I want to do is basically having an image that works as container for each tableview row like in the following picture. Since the content for each row is different, the image should be resized in height to contain the text of the cell.
I am wondering what is the best practice to achieve it.
Thanks in advance
Have a background image view for the cell and set the frame size based on the content you have to place inside the cell. Then you can use the "stretchableImageWithLeftCapWidth:topCapHeight:" method to create the image that you want to set the cell background.
UIImage *backgroundImg = [[UIImage imageNamed:#"test.png"] stretchableImageWithLeftCapWidth:30 topCapHeight:20];
[cell.bgImageView setFrame:CGRectMake(a, b, c, d];
cell.bgImageView.image = backgroundImg;
Yo can use method sizeToFit for this image. else use the image type as center or scaleToFit.

Where to set tableView.rowHeight?

I'm trying to figure out where to properly set tableView.rowHeight. Currently I have it in my ViewDidLoad method, but as I am using images it seems to be scaling the images up from the default.
E.g. my cell images are 55px squared. But if I set [self.tableView.rowHeight = 55.0]; in ViewDidLoad, they look a bit blurry.
You have to make space for the table view separator line (that is 1px), so if your image height is 55px, your table row height needs to be 56px.

Custom UITextField

How would I go about creating a UITextField like the one in this image?
It appears to be slightly larger, specifically in height.
This can be done much better and simpler with a stretchable image:
UIImage *fieldBGImage = [[UIImage imageNamed:#"input.png"] stretchableImageWithLeftCapWidth:20 topCapHeight:20];
[myUITextField setBackground:fieldBGImage];
Think of the background of the text field as split into three sections. A middle section which can be stretched and caps on the ends. Create an image which only needs to be long enough to contain one pixel of this repeating section (a very short text field), and then create a stretchable image from it using stretchableImageWithLeftCapWidth: topCapHeight. Pass the width of the left end cap into 'leftCapWidth.' You can make it stretch vertically as well, but if your background image is the same height as your text box it wont have an effect.
If you're familiar with 9-slice scaling in Flash or Illustrator it's exactly the same concept, except the middle sections are only one pixel wide/tall.
The advantage of this is you don't have to worry about multiple layered objects scaling together and you can resize your text fields any time and the background will stay in tact. It works on other elements too!
You probably want to use the background and borderStyle properties of UITextField. Setting borderStyle as UITextBorderStyleNone and create a custom background image to be stretched and used as the background property would be one approach.
I suggest taking a look at those properties in the UITextField class reference.
You can do this by:
yourTextField.borderStyle = UITextBorderStyleNone;
yourTextField.background = [UIImage imageNamed:#"email-input.png"];
And if you want to give margin to your text inside the textfield, you can do this by:
// Setting Text Field Margins to display the user entered text Properly
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
yourTextField.leftView = paddingView;
yourTextField.leftViewMode = UITextFieldViewModeAlways;
You can also do this through Interface Builder.
just use the following line and it should work
textfield_name.background = [UIImage imageNamed : #"yourImage.png"];
here, "yourImage" is the background image you wanna set...
however, this will work only if your button isnt a roundrect button.So, you can change the type of the button in the Interface Builder or you can use
textfield_name.borderstyle = UITextBorderStyleNone or UITextBorderStyleBezel
and you r gud2go....!
Take an uiimageview set its image property to the image you want as uitextfield background. And on top of this uiimageview place an uitextfield with borderstyle none. This you can do directly in interface builder.

UITableViewCell strange width?

I have setup a UITableView (320 wide) with a UITableViewCell created in IB, the cell is also 320 wide. After setting a background image (320 wide) in UITableViewCell (or my subclass to be correct) I have noticed that the cells fall short of the right hand side of the UI (notice the blue on the selected cell and the grey on the one above) Does anyone know what is causing this?
Cheers Gary
I was setting the seperator style and the seperator color on the UITableView, this takes 1 pixel off the cell height for the seperator and offsets the backgound by about 5 pixels to the right. If I reduce the background image thats going into the cell from 320x65 to 320x64 it fits perfectly with no offset.
The only difference between the two screens below is:
LEFT: UITableView Seperator = "None" (UITableViewCell background has no offset)
RIGHT: UITableView Seperator = "Single Line" (UITableViewCell background has offset)
DATA:
Cell resolution: 320x65
Cell view: 320x65
Cell Background Image Resolution: 320x65
If you want use the separator your Cell Background Image needs to be 320x64, this will stop it shifting sideways and display the cell correctly.
Cheers Gary
It seems to me that you're just not setting the contentMode of your background image view correctly (i.e. you're setting it to aspectFit or something). Are you sure that it's offset by 5, and not actually shrunk by 5 pixels?
For example, if the original picture is 320x65, and the height is reduced to 64, aspectFit will scale it, while keeping the same aspect ratio, to 64/65 * 320 ~= 315.

Drop shadows on iPhone Clock App "Alarm" tab

In the clock app that comes with the iPhone there is a tab view for setting alarms. In that view each of the UITableViewCell instances have a drop shadow around them. Does anyone know how to achieve the same effect?
Also it looks like the tab bar at the very bottom has a drop shadow above it as well.
Ideas on how to achieve the same look would be greatly appreciated.
I was wondering how to do that and it just occurred to me to use the UITableView's footer view:
myTableView.tableFooterView = myCustomViewWithDropShadowImage;
I would guess that there is an extra cell which contains just a background image which is the transparent dropshadow. If it's not a cell (because that might create scrolling weirdness) it is probably an extra view positioned below the bottom cell of the UITableview which - again - simply contains an image of the drop shadow.
Like Thomas said, create a 100% width image (say, 320 x 40px on non-retina devices) and create 4 instances of UIImageView with it. The first, at the top of your main view. The second, at the bottom, and in addition do this:
UIImageView* bottomShadow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"BottmShadow.png"]]
bottomShadow.transform = CGAffineTransformMakeScale(1, -1);
(Flip it vertically)
Then, do the same with the other two, but place them as subviews of the Table View. One of them just outside the first row:
CGRect tableTopShadowFrame = tableTopShadow.frame;
tableTopShadowFrame.origin.y = -(tableTopShadowFrame.size.height);
[tableTopShadow setFrame:tableTopShadowFrame];
and the other just below the last row (you need to know the height of all the rows together. If your rows are all the same height, it is row height times number of rows).
Finally, you need to set the table's backgroundColor property to transparent
tableView.backgroundColor = [UIColor clearColor];
and possibly set some darkish gray for your main view's background color.