滚动后的圆形图像

时间:2014-01-26 17:13:02

标签: ios uiimage uitableview

我在设置TableView Controller时遇到了严重问题。我想在我的自定义单元格中显示圆形轮廓图片,但它是平方的,直到我将单元格滚出屏幕。滚动后,我的图像应该是圆形的。

希望有人可以帮助我,也许会尝试解释UITableView如何重用自定义单元格?

以下是我的ViewController中的代码:

#import "ViewController.h"
#import "Cell.h"

@interface ViewController ()

@end

@implementation ViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *CellIdentifier = [NSString stringWithFormat:@"%d",indexPath.row];
    NSLog(@"Cell wird erstellt");

    Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[Cell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
    }



    NSLog(@"BildCheck");

    // Set up the cell…
    switch (indexPath.row) {
        case 0:
            cell.primaryLabel.text = @"Meeting on iPhone Development";
            cell.secondaryLabel.text = @"Sat 10:30";
            break;
        case 1:
            cell.primaryLabel.text = @"Call With Client";
            cell.secondaryLabel.text = @"Planned";
            break;
        case 2:
            cell.primaryLabel.text = @"Appointment with Joey";
            cell.secondaryLabel.text = @"2 Hours";
            break;
        case 3:
            cell.primaryLabel.text = @"Call With Client";
            cell.secondaryLabel.text = @"Planned";
            break;
        case 4:
            cell.primaryLabel.text = @"Appointment with Joey";
            cell.secondaryLabel.text = @"2 Hours";;
            break;
        default:
            break;
    }

    NSString *imageString = [NSString stringWithFormat:@"http://localhost/tobi.jpg"];
    NSURL * imageURL = [NSURL URLWithString:imageString];
    NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
    UIImage * image = [UIImage imageWithData:imageData];
    [cell.myImageView setImage:image];

    NSLog(@"Anfang Rund");
    cell.myImageView.center = self.view.center;
    cell.myImageView.layer.cornerRadius = roundf(cell.myImageView.frame.size.width/2.0);
    cell.myImageView.layer.masksToBounds = YES;
    NSLog(@"Ende Rund");








    return cell;

}

@end

0 个答案:

没有答案
相关问题