[分享]iOS開發-UImageview加邊框加陰影

ShevaKuilin發表於2016-03-01

初始化

UIImageView *imgvPhoto  = [UIImageView alloc] init];

新增邊框

CALayer *layer = [_imgvPhoto layer];
layer.borderColor = [[UIColor whiteColor] CGColor];
layer.borderWidth = 5.0f;

新增四個邊陰影

_imgvPhoto.layer.shadowColor = [UIColor blackColor].CGColor;
_imgvPhoto.layer.shadowOffset = CGSizeMake(0, 0);
_imgvPhoto.layer.shadowOpacity = 0.5;
_imgvPhoto.layer.shadowRadius = 10.0;

新增兩個邊陰影

_imgvPhoto.layer.shadowColor = [UIColor blackColor].CGColor;
_imgvPhoto.layer.shadowOffset = CGSizeMake(4, 4);
_imgvPhoto.layer.shadowOpacity = 0.5;
_imgvPhoto.layer.shadowRadius = 2.0;

設定layer

CALayer *layer=[backView layer]; 

是否設定邊框以及是否可見

[layer setMasksToBounds:YES];

設定邊框圓角的弧度

[layer setCornerRadius:10.0];

設定邊框線的寬

[layer setBorderWidth:1];

設定邊框線的顏色

[layer setBorderColor:[[UIColor blackColor] CGColor]];

分享來源:

http://www.cnblogs.com/Rampag…

相關文章