2013-04-19 9 views
8

Ehi tutto quello che sto cercando di impostare cell.imageView 's cornerRadius, ma non sembra funzionare.iOS UITableViewCell cell.imageVisualizzazione impostazione angolo arrotondato

cell.imageView.layer.cornerRadius=9; 

Funzionerà o dovrei aggiungere un personalizzato UIImageView nella mia cella per avere angoli arrotondati?

Ho anche provato questo

cell.imageView.layer.borderWidth=2; 
cell.imageView.layer.borderColor=[[UIColor blackColor]CGColor]; 

Ma anche non sembra funzionare. Qualcuno ha affrontato un problema simile?

+4

è necessario impostare 'masksToBounds' pure. Hai letto la documentazione di 'CALayer'? – Desdenova

+0

@Desdenova Scusa se ho dimenticato una cosa di base, grazie :). – satheeshwaran

risposta

27

Prima add Framework -> QuartzCore.framework al progetto
quindi importare file di intestazione nel file ViewController.m

#import <QuartzCore/CALayer.h> 

Add seguente codice nel tuo cellForRowAtIndexPath metodo:

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

    NSString *cellIdentifier = @"TableViewCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 

     // Rounded Rect for cell image 
     CALayer *cellImageLayer = cell.imageView.layer; 
     [cellImageLayer setCornerRadius:9]; 
     [cellImageLayer setMasksToBounds:YES]; 
    }         

    cell.imageView.image = [UIImage imageNamed:@"image_name.png"]; 

    return cell; 
} 
+3

Grazie, ho appena perso setMasksToBounds. Fatto un terribile errore – satheeshwaran