Apollo
Apollo

Reputation: 9064

changing corner radius of uitableview grouped in iOS6

I've tried using the following code but with no luck. Anybody know how to do this in iOS 6? I do not want to create a custom cell.

self.tableView.layer.cornerRadius = 5.0f;
    [self.tableView setClipsToBounds:YES];

Edit:

It appears that what's actually happening is that this code is creating a corner radius for the entire view, not each individual UITableViewSection. Does this make sense?

I have also tried [cell.layer setCornerRadius:3.0]; but also with no luck. The corners of my UITableView are still exactly the same.

enter image description here

Upvotes: 8

Views: 16076

Answers (10)

Vandit Mehta
Vandit Mehta

Reputation: 2587

Add this to your .h file

#import <QuartzCore/QuartzCore.h>

And use below in your code,

tblView.layer.cornerRadius=5.0f;

Upvotes: 3

Aish
Aish

Reputation: 189

instead of setting the corner radius of the cell, set the radius for the cell.contentview as follows:

cell.contentView.layer.cornerRadius = 10.0f;
cell.contentView.layer.borderColor = [UIColor blackColor].CGColor;
cell.contentView.layer.borderWidth = 3.0f;

put the above code while initializing the cell.

Upvotes: 3

Prince Kumar Sharma
Prince Kumar Sharma

Reputation: 12641

who said [_tblView.layer setCornerRadius:10.0]; is not working in grouped style tableView.

Write this code and you will set setCornerRadius also works in grouped tableView.

[_tblView setBackgroundView:nil];
[_tblView setBackgroundColor:[UIColor greenColor]];
[_tblView.layer setCornerRadius:10.0];

enter image description here

[_tblView.layer setCornerRadius:10.0]; will not create corner radius for particular section of tableView this is for setting corner radius of whole tableView.

Upvotes: 5

DennyLou
DennyLou

Reputation: 106

I think PrettyKit is what you're looking for. Fully customisable and fast. https://github.com/vicpenap/PrettyKit give it a go. Should do the job properly.

Upvotes: 2

juanjo
juanjo

Reputation: 3757

You can change de backgroundView of the TableViewCell, create a subclass of UIView and change the layer class:

@interface BackgroundView : UIView
@end

@implementation BackgroundView

+ (Class)layerClass
{
    return [CAShapeLayer class];
}
@end

later in cellForRowAtIndexPath you do something like this:

static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

CGRect frame = cell.backgroundView.frame;
cell.backgroundView = [[BackgroundView alloc] initWithFrame:frame];

CGFloat corner = 20.0f;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:cell.backgroundView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(corner, corner)];
CAShapeLayer  *shapeLayer = (CAShapeLayer *)cell.backgroundView.layer;
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = cell.textLabel.backgroundColor.CGColor;
shapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;
shapeLayer.lineWidth = 1.0f;

return cell;

Results this:

enter image description here

You can modify the corners you want or create another path.

I hope it helps.

Upvotes: 19

Chaman Sharma
Chaman Sharma

Reputation: 636

Try this:-

tableView.layer.cornerRadius=5.0f;

Upvotes: 1

Charlie Abcd
Charlie Abcd

Reputation: 83

You can do by this. Its working for me

    UILabel *delLbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 44)];
    delLbl.font = [UIFont fontWithName:@"Arial-BoldMT" size:18];
    delLbl.layer.cornerRadius = 10.0f;
    delLbl.layer.borderWidth = 1.0f;
    delLbl.layer.borderColor = [UIColor grayColor].CGColor;
    delLbl.text = @"Cell Text";
    delLbl.textAlignment = NSTextAlignmentCenter;
    [cell.contentView addSubview:delLbl];
    cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
    Return Cell;

Upvotes: 2

Jitendra
Jitendra

Reputation: 5081

First you Need to use the QuartzCode Framework Import that Framework ANd Declare .h File Which class you wanted to set the Layer Effect.

And Add that Method

myTableView.layer.cornerRadius=5;
[myTableView setClipsToBounds:YES];

and if you want to set corner radious to cell also tried this code

UITableViewCell.layer is kind of class CALayer and CALayer class have a property called cornerRadius. so you set the cell's corner radius as fallows:

[cell.layer setCornerRadius:3.0];

Try this code.

Upvotes: 2

nithinbhaktha
nithinbhaktha

Reputation: 723

I think you are missing this line of code :

[self.tableView.layer setMasksToBounds:YES];

Upvotes: 2

naveen
naveen

Reputation: 59

add quartzcore framework to your project

import QuartzCore/QuartzCore.h to your .h file

self.tableView.layer.cornerRadius = 5.0f;

Upvotes: 2

Related Questions