When i used
self.view.backgroundColor = [UIColor colorWithPatternImage:
[UIImage imageNamed:#"image_name.png"]];
the cell carry bottom part of image and it looks like strip on view
Use the following method to set cell height exactly the same as your image's height:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Also you might want to remove separators depending on how your image looks using the following code:
MyTableName.separatorStyle = UITableViewCellSeparatorStyleNone;
Related
Following is the image i have taken from an app from the App Store:
I have created an app that is using StoryBoard with custom tableview cell. The data is loaded in it from a web service. This is what i want:
1) How can i change the size of the uitableviewcell according to the image? For example if one image is 640*500, then the UITableViewCell will change its size accordingly. If the size if the image is 640*1000, then the cell should change its size accordingly.
2) How can i add the grey coloured border around the tableview cells just like in the image above?
3) How can i add a shadow dropping from the UITableViewCell just like in the image above?
Thanks!
Currently i have a partial answer to your question. Part 2 of the question that is the colored border can be solved by the following code:
[cell.contentView.layer setBorderColor:[UIColor colorWithRed:222/255.0f green:222/255.0f blue:222/255.0f alpha:1.0f].CGColor];
[cell.contentView.layer setBorderWidth:5.0f];
Part-1
The height of the tableviewcell is determined using
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
/*
Get the image size
CGFloat width = myImage.size.width;
CGFloat height = myImage.size.height;
use this to return the height of your cell.
*/
}
Part-2 and Part-3
Use..
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
//This will give you access to the cell being rendered and any customization you want can be done here... You can use the earlier answer for this part.. I havent tried it but should work..
}
Hope this helps..
I'm managed to make my UITableView rows / cells black when data is loaded, to a fashion, I get a white line in between rows, which makes it look awful. How can i make them fully black with and without data ?
Heres the code I'm using at the moment
- (void)tableView:(UITableView *)tableView willDisplayCell:
(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor blackColor];
}
Heres what I get (with white lines remaining) :(
Change the separator style of your table view.
yourTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
You can do it in Interface Builder too on the properties palette.
-- Edit for clarity following comments below --
Set the entire tableView to have a black background:
[yourTableView setBackgroundColor:[UIColor blackColor]];
This can also be done in the Interface Builder properties panel.
I'm loading a custom nib file to customize the cells of a UITableView. The custom nib has a UILabel that is referenced from the main view by tag. I would like to know if it is possible to change the shadow color of the UILabel when the cell is selected to a different color so it doesn't look like in the screenshot.
I prefer to make the shadow color change inside the TableCell code to not pollute the delegate. You can override this method to handle it:
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animate
{
UIColor * newShadow = highlighted ? [UIColor clearColor] : [UIColor whiteColor];
nameLabel.shadowColor = newShadow;
[super setHighlighted:highlighted animated:animate];
}
You could change the label's shadow color in -tableView:willSelectRowAtIndexPath: in the delegate. For instance:
-(NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.shadowColor = [UIColor greenColor];
return indexPath;
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.shadowColor = [UIColor redColor];
}
I had the same issue and none of the above solutions quite worked for me - I didn't want to subclass UITableViewCell and also had some tricky selected/highlighted state changes done programmatically, which did not play well with the solutions above.
MySolution:
What I did in the end is to use a second UILabel underneath the primary UILabel to act as a shadow. For that 'shadow' UILabel you can set the 'Highlighted Color' to 'Clear Color'.
Obviously you have to update the shadow label each time you update the primary label. Not a big price to pay in many cases.
Hope that helps!
The simple answer, at least for the example shown above, is to not display the shadow in the first place. Since you can't see the white-on-white anyway, set the shadowColor to -clearColor.
If you actually need a shadow though, overriding the -setHighlighted method is the best solution. It keeps the code with the cell, which I think is better than trying to handle it from the table view.
I tried all this inside
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
1.tableView.backgroundColor = [UIColor clearColor];
2.cell.backgroundColor = [UIColor clearColor];
3.cell.contentView.backgroundColor = [UIColor clearColor];
It only responds to the 1st line and makes the background a translucent kind of black. What should I do to get 100% transparency?
I've had this same problem before. As suggested in a comment, try [setOpaque:NO]
If push comes to shove, make a simple 1px clear .png. Then, make a stretchable UIImage with it, and say [setBackgroundView:imageViewWithClearImage]. That's a bit hacky, though.
I have a grouped UITableView that has 3 sections. I would like to show a UIImage with some text next to it (not a cell), but I am not sure how I can go about doing that? The image and text need to match the background of the pinstripes.
A UITableView has a backgroundView property that it uses to display the pinstripes for the grouped style. You can either replace the background view or add to it. If you replace it, you lose the pinstripes.
[myTable.backgroundImage addSubview:myImage];
[myTable.backgroundImage addSubview:myLabel];
You don't have to define a custom cell, you can use a standard UITableViewCell. It has properties for text and an image. Assign the image to the imageView property, put the text in the textLabel property.
Depending on the size of your image and your desired placement, you can use the imageView property of the UITableViewCell. Essentially, your cellForRowAtIndexPath will look like this:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Normal cell setup
cell.imageView.image = myImage;
cell.textLabel.text = imageDescription;
return cell;
}
That will create a cell with an image at the left edge with text after it in the middle/right edge
[self.tableView addSubview:myImageView];
[Self.tableView sendSubviewToBack:myImageView];
Or
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:"myimage.png"]];
Use Photoshop to place something on top of an image of the pinstripes.