您可以設置shadowPath屬性跟蹤該ICONVIEW路徑,並設置其圓角半徑也,就像這樣:
UIImageView * iv = [UIImageView new];
iv.frame = CGRectMake(0, 0, 100, 50);
iv.backgroundColor = [UIColor redColor];
iv.layer.cornerRadius = 10.0f;
iv.image = [UIImage imageNamed:@"settings-120.png"];
iv.layer.cornerRadius = 10.0f;
iv.layer.shadowColor = [UIColor blackColor].CGColor;
iv.layer.shadowOffset = CGSizeZero;
iv.layer.shadowRadius = 3.0f;
iv.layer.shadowOpacity = 1.0f;
iv.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:iv.bounds cornerRadius:iv.layer.cornerRadius].CGPath;
[self.view addSubview:iv];
如果你想設置與UIViewContentModeScaleAspectFill圖像(並沒有它溢出),然後將它嵌入持有人,設置持有人的影子和夾圖像查看:
UIView * holder = [UIView new];
holder.frame = CGRectMake(0, 0, 100, 50);
holder.layer.cornerRadius = 10.0f;
holder.layer.shadowColor = [UIColor whiteColor].CGColor;
holder.layer.shadowOffset = CGSizeZero;
holder.layer.shadowRadius = 3.0f;
holder.layer.shadowOpacity = 1.0f;
holder.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:holder.bounds cornerRadius:holder.layer.cornerRadius].CGPath;
[self.view addSubview:holder];
UIImageView * iv = [UIImageView new];
iv.frame = holder.bounds;
iv.layer.cornerRadius = holder.layer.cornerRadius;
iv.image = [UIImage imageNamed:@"settings-120.png"];
iv.contentMode = UIViewContentModeScaleAspectFill;
iv.clipsToBounds = true;
[holder addSubview:iv];
檢查此https://stackoverflow.com/questions/40887532/how-to-give-an-imageview-in-swift3-0-1-shadow-at-the-same-time-with-rounded-corn –
這是迅速的答案。 – birdcage
[UIView可能有重複的圓角和陰影?](https://stackoverflow.com/questions/4754392/uiview-with-rounded-corners-and-drop-shadow) – DonMag