Remove rounded corners UITableViewCell - ios

I've been trying to do this for a while now. I just want to remove the rounded corners you can see on this picture :
Does anyone know how to do it ?
[EDIT 1 : CELL BUILDING]
I am subclassing UITableViewCell to make my own layout. And then I'm adding a background to these cells like below :
UIImageView* imageView = [ [ UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320.0, 44.0)];
imageView.image = cellBackground;
cell.backgroundView = imageView;

I you need to edit the backgroundview of the corresponding cell. E.g.
UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
bg.backgroundColor = [UIColor whiteColor]; // or any color
cell.backgroundView = bg;
[bg release];

The corners aren't rounded by default, just so you know.
Do you have a background image for the cell that makes the corners
seem rounded (most likely)?
Is each cell actually a section of the
tableview and there is no space between them?
Are you testing on a
jailbroken iPhone and you have some winterboard theme installed that
changes the style of tableviews?

Related

Disable highlight button in uitableviewcell when select row

I have custom UITableViewCell and two buttons inside. When I select row, background for buttons change for the same color as background of selected row, and border for buttons disappears.
How Can I disable change border/background color for button when row is selected ?
Thanks for reply
1) Create a UIView and assign the desired background color.
2) Render the UIView to an UIImage
3) Set the backgroundImage of the button for the desired state.
UIView *colorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
colorView.backgroundColor = color;
UIGraphicsBeginImageContext(colorView.bounds.size);
[colorView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *colorImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[button setBackgroundImage:colorImage forState: UIControlStateHighlighted];
I achieved this using a clear background view for my cells and disabling selection color of the row, but I needed it that way. Don't know if it suits your need, but you can try this:
UIView *selectedView = [[UIView alloc] initWithFrame:cell.bounds];
selectedView.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = selectedView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Hope this helps.
Do checkout this thread as well : Why do all backgrounds disappear on UITableViewCell select?

Overlay textLabel and UIImageView in UITableViewCell

I have a problem positioning a textLabel and detailTextLabel into a custom UITableViewCell that has a UIImageView appearing behind the textLabel and detailTextLabel.
Refer to the image - it will make more sense
--> what you're looking a UITableView, where each bubble represents a different UITableViewCell.
Essentially, I am trying to fit the textLabel and detailTextLabel into the bubble you see by expanding the bubble dimensions. However, no matter what I try the bubble will not change it's width and height even if I change the UIImageView frame or bounds or contentMode.
Here is the relevant code in cellForRowAtIndexPath:
//Set font and style
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
// Assign our own background image for the cell
UIImage *cellBackgroundImage = [UIImage imageNamed:#"Chat.png"];
UIImageView *cellBackgroundImageView = [[UIImageView alloc] initWithImage:cellBackgroundImage];
//[cellBackgroundImageView setBounds:CGRectMake(0, 0, 20, 20)];
//[cellBackgroundImageView setImage:cellBackgroundImage];
//cellBackgroundImageView.frame = CGRectMake(cellBackgroundImageView.frame.origin.x, cellBackgroundImageView.frame.origin.y, 20, 20);
//cellBackgroundImageView.bounds = CGRectMake(cellBackgroundImageView.frame.origin.x, cellBackgroundImageView.frame.origin.y, 0, 0);
cellBackgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
cellBackgroundImageView.image = cellBackgroundImage;
cell.backgroundView = cellBackgroundImageView;
Any help would be appreciated.
Don't do it here, I did it by writing frame of image and label in LayoutSubviews method in custom cell class.
Just
-(void)layoutSubviews
{ setframe: for both UI components }
Dont use Aspect FIll, use either scaleToFill, or set image to image view using imageCapInsets .
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode
For your Image, it must be like
UIImage *cellBackgroundImage = [[UIImage imageNamed:#"Chat.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 70, 40, 20) resizingMode:UIImageResizingModeStretch]

Adding a UIImageView as a subview of UILabel, image not appearing

So, when I do this with a regular old view:
UIView *topBlock = [[UIView alloc] initWithFrame:CGRectMake(0,-frameSize.height, frameSize.width, frameSize.height/2)];
[viewController.view addSubview:topBlock];
topBlock.autoresizesSubviews = NO;
topBlock.clipsToBounds = YES;
UIImage *topImage = [UIImage imageNamed:#"BloktLayout"];
UIImageView *topImageView = [[UIImageView alloc] initWithImage:topImage];
topImageView.frame = viewController.view.frame;
[topBlock addSubview:topImageView];
I get the nice old image where I want it, in the top view. But the middle view is a UILabel, and when I try the same thing:
UILabel *midBar = [[UILabel alloc] initWithFrame:CGRectMake(midBarOrigin.x, midBarOrigin.y, midBarWidth, midBarHeight)];
midBar.text = #"Blokt";
midBar.textColor = [UIColor blackColor];
midBar.textAlignment = NSTextAlignmentRight;
midBar.font = [UIFont fontWithName:#"HelveticaNeue-UltraLight" size:80.0f];
[viewController.view addSubview:midBar];
midBar.autoresizesSubviews = NO;
midBar.clipsToBounds = YES;
UIImage *midImage = [UIImage imageNamed:#"BloktLayout"];
UIImageView *midImageView = [[UIImageView alloc] initWithImage:midImage];
midImageView.frame = viewController.view.frame;
[midBar addSubview:midImageView];
I don't see any image at all in the UILabel. Any help?
Seems like the issue is related to your frames.
Tough to say without additional info. Can you post viewController.view.frame, frameSize, and midBarOrigin / midBarWidth / midBarHeight?
In the second codeblock, midBar.clipsToBounds == YES, but it looks like the midImageView.frame is likely very different / outside of midBar.frame in which case it wouldn't be visible.
Edit Some screenshots would help but aren't necessary
Edit 2 Note that subviews' origin points are always relative to the coordinate system of their superview, never relative to the coordinate system of any other view in the view heierarchy. This is likely the heart of the issue here. If you do want to convert CGPoints or CGRects from one coordinate system to another there are methods on UIView such as convertRect: and convertPoint: etc.
Interface Builder doesn't even let you add a control inside of a UILabel.
Instead, if you wish to group multiple controls, you can add them both as subviews of a UIView.
In other words, your image view and label can share the same superview, but the image view cannot be a subview of the label.
If they share the same superview, you can position the image view behind the label, and it should appear "through" the label as long as the label's background is clear.
Simple Way to do.....
You can add UIImageView, UILabel as subview of cell.textLabel
UIImageView *statusImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 4, 8, 8)];<br/>statusImage.backgroundColor = [UIColor redColor];<br/>
statusImage.layer.cornerRadius = 4;<br/>
statusImage.clipsToBounds = YES;<br/>
[cell.textLabel addSubview:statusImage];<br/>
UILabel *Lbl = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, cell.textLabel.frame.size.width - 15, cell.textLabel.frame.size.height)];<br/>
Lbl.text = #"xyz";<br/>
[cell.textLabel addSubview:Lbl];<br/>
I just had this problem as well.
I found that ImageView was behind the label.
When I replaced label with UIView, it works properly.

UILabel in UITableView

My question is how to add a gray edge to each label on (UITableViewCell that contains many 3 labels)?
So that my labels for each cell will be sepraeted by the edge.
You can have a UIView as content of UITableViewCell by adding subviews to contentView property of UITableViewCell.
Add your labels as subviews to the cell and to have separators in between labels you can use this kind of code
UIView* vertLineView = [[UIView alloc] initWithFrame:CGRectMake(80, 0, 1, 44)];
vertLineView.backgroundColor = [UIColor redColor];
[self.contentView addSubview:vertLineView];
Reference:Draw vertical separator on UITableViewCell
Hope this solves your problem.
If you only want to separate the labels from each other, you could add a UIImageView between them with a small width (like 1 or 2 points) with a dark picture. If you want them to have border, set:
myLabel.layer.borderColor = [UIColor blackColor];
myLabel.layer.borderWidth = 1.0;
Don't forget to include QuarzCore.

Dark Corners UITableViewController

I have a UITableViewController. In viewDidLoad, I do the following:
self.tableView.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg_cafe.png"]];
The background is supposed to be a gradient. Two issues:
Gradient seems to get cut off at the end of the UITableView.
The corners are tinted.
I've experimented with setting the UITableCell's opacity to NO, but that doesn't worked. I have read these threads already: Transparent background in grouped UITableView - iPhone, and Black corners around UITableViewCells.
I'm not using Interface Builder at all for this.
Example:
Make a UIView with that pattern image as background color and set it as table view's background view.
UIView *bgView = [[UIView alloc] initWithFrame:self.tableView.frame];
bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg_cafe.png"]];
self.tableView.backgroundView = bgView;
[bgView release];

Resources