2013-04-19 9 views
8

Hej wszystko próbuję ustawić cell.imageView 's cornerRadius, ale to nie wydaje się działać.iOS UITableViewCell cell.imageView ustawienie zaokrąglonego rogu

cell.imageView.layer.cornerRadius=9; 

to będzie działać czy muszę dodawać niestandardowe UIImageView w celi mieć zaokrąglone rogi?

Próbowałem również ten

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

Ale to również nie wydają się działać. Czy ktoś miał podobny problem?

+4

trzeba ustawić 'masksToBounds' również. Czy przeczytałeś dokumentację "CALayer"? – Desdenova

+0

@Desdenova Przepraszam, zapomniałem o podstawowej rzeczy, dzięki :). – satheeshwaran

Odpowiedz

27

Pierwszy add Framework -> QuartzCore.framework do projektu
następnie import pliku nagłówka w pliku ViewController.m

#import <QuartzCore/CALayer.h> 

Dodaj następujący kod w swoim sposobie cellForRowAtIndexPath:

- (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

Dzięki, właśnie przegapiłem setMasksToBounds. Popełniłem straszny błąd. – satheeshwaran

Powiązane problemy