Reputation: 3653
I have an UITableView
with UITableViewCell
and I want to make cell.imageView
as circles. So I did this in my cellForrowAtIndex
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
}
cell.backgroundColor=[UIColor clearColor];
cell.imageView.layer.cornerRadius=cell.imageView.frame.size.width/2;
cell.imageView.layer.masksToBounds=YES;
cell.imageView.layer.borderWidth = 2.0f;
cell.imageView.layer.borderColor=[UIColor whiteColor].CGColor;
But when load the table UIImage
s are squares and then when I scroll it become circles. How can I solve this problem?
Please help me.
Thanks
Upvotes: 1
Views: 688
Reputation: 1821
try this code
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(-30, 40, 100, 100)];
imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
imageView.layer.masksToBounds = YES;
imageView.layer.cornerRadius = 50.0;
imageView.layer.shadowRadius=5;
imageView.layer.shadowOpacity=4;
imageView.layer.shadowColor=(__bridge CGColorRef)([UIColor blackColor]);
imageView.layer.borderColor = [UIColor whiteColor].CGColor;
imageView.layer.borderWidth = 3.0f;
imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;
imageView.layer.shouldRasterize = YES;
imageView.clipsToBounds = YES;
Upvotes: 0
Reputation: 192
Below is the code
[cell.imgview setImage:[UIImage imageWithData:imgData]];
cell.imgview.layer.cornerRadius = cell.img_userpic.frame.size.height /2;
cell.imgview.layer.masksToBounds = YES;
cell.imgview.layer.borderWidth = 0;
Your Imageview's width and height should be same otherwise it won't display circle.
Upvotes: 1
Reputation: 8914
You need to create a custom cell by inheriting UITableViewCell
and then configure cell in that class.
Implement awakeFromNib
method in it and set your image view as you need in this method.
Upvotes: 0
Reputation: 4402
Use below line of code in your cellForRow Method. For circle you have to set cornerradius of layer and set clipsToBounds property to YES
.
cell.imageView.clipsToBounds = YES;
Upvotes: 0