UIView和UIImageView 旋转消除锯齿方法

方法一:
calendarImageView_ =[[UIImageView alloc] initWithFrame:CGRectMake(3,3,60,72)];
    calendarImageView_.image =[UIImage imageNamed:@"tc_news_tilt_plate.png"];
    calendarImageView_.image = previewImage_;
    calendarImageView_.layer.shadowOffset =CGSizeMake(0,2);
    calendarImageView_.layer.shadowRadius =2.0;
    calendarImageView_.layer.shadowColor =[UIColor whiteColor].CGColor;
    calendarImageView_.layer.shadowOpacity =0.8;
    calendarImageView_.layer.borderColor =[UIColor clearColor].CGColor;
    calendarImageView_.layer.borderWidth =2.0;
    calendarImageView_.layer.cornerRadius =3.0;
    [calendarImageView_.layer setShouldRasterize:YES];
    calendarImageView_.transform =CGAffineTransformMakeRotation(degreesToRadians(-16));
    [self addSubview:calendarImageView_];



方法二:

 
-(void)drawRect:(CGRect)rect {
    // Drawing code.
    
    CALayer*sublayer =[CALayer layer];
    sublayer.backgroundColor =[UIColor clearColor].CGColor;
    sublayer.shadowOffset =CGSizeMake(0,1);
    sublayer.shadowRadius =2.0;
    sublayer.shadowColor =[UIColor redColor].CGColor;
    sublayer.shadowOpacity =0.8;
    sublayer.frame =CGRectMake(3,3,60,72);
    [sublayer setShouldRasterize:YES];
    sublayer.borderColor =[UIColor clearColor].CGColor;
    sublayer.borderWidth =2.0;
    sublayer.cornerRadius =10.0;
    [sublayersetTransform:CATransform3DMakeAffineTransform(CGAffineTransformMakeRotation(degreesToRadians(-16)))];
    //sublayer.edgeAntialiasingMask = kCALayerLeftEdge|kCALayerRightEdge|kCALayerBottomEdge|kCALayerTopEdge;
    [self.layer addSublayer:sublayer];
    
    
    CALayer*imageLayer =[CALayer layer];
    imageLayer.frame = sublayer.bounds;
    imageLayer.cornerRadius =6.0;
    imageLayer.contents =(id)previewImage_.CGImage;
    imageLayer.masksToBounds = YES;
    [sublayer addSublayer:imageLayer];
}

posted @ 2013-09-24 12:54  yingkong1987  阅读(1144)  评论(0编辑  收藏  举报