1
我在網上看過,但是我的結果主要包含「如何做一個shadowOffset」。我需要將「陰影,邊框和CornerRadius」應用於我的視圖中的多個對象。我只想看看是否有更有效的方法?或者,如果能夠使它更有條理。繼承我的一些代碼。請記住,我有這樣的多個視圖,所以這段代碼佔用的空間量非常煩人。UIViewController上有多個shadowOffset
topView.layer.cornerRadius = 3;
topView.layer.masksToBounds = YES;
topView.layer.borderColor= [UIColor lightGrayColor].CGColor;
topView.layer.borderWidth = 0.5f;
bottomView.layer.cornerRadius = 3;
bottomView.layer.masksToBounds = YES;
bottomView.layer.borderColor= [UIColor lightGrayColor].CGColor;
bottomView.layer.borderWidth = 0.5f;
eventName.layer.masksToBounds = NO;
eventName.layer.shadowColor = [UIColor blackColor].CGColor;
eventName.layer.shadowOpacity = 0.5;
eventName.layer.shadowRadius = 2;
//(right,down) also (-right,-down)
eventName.layer.shadowOffset = CGSizeMake(0.0f, 0.8f);
addressLabel.layer.masksToBounds = NO;
addressLabel.layer.shadowColor = [UIColor blackColor].CGColor;
addressLabel.layer.shadowOpacity = 0.5;
addressLabel.layer.shadowRadius = 2;
//(right,down) also (-right,-down)
addressLabel.layer.shadowOffset = CGSizeMake(0.0f, 0.8f);
dateLabel.layer.masksToBounds = NO;
dateLabel.layer.shadowColor = [UIColor blackColor].CGColor;
dateLabel.layer.shadowOpacity = 0.5;
dateLabel.layer.shadowRadius = 2;
//(right,down) also (-right,-down)
dateLabel.layer.shadowOffset = CGSizeMake(0.0f, 0.8f);
typeLabel.layer.masksToBounds = NO;
typeLabel.layer.shadowColor = [UIColor blackColor].CGColor;
typeLabel.layer.shadowOpacity = 0.5;
typeLabel.layer.shadowRadius = 2;
//(right,down) also (-right,-down)
typeLabel.layer.shadowOffset = CGSizeMake(0.0f, 0.8f);
eventCaption.layer.masksToBounds = NO;
eventCaption.layer.shadowColor = [UIColor blackColor].CGColor;
eventCaption.layer.shadowOpacity = 0.5;
eventCaption.layer.shadowRadius = 2;
//(right,down) also (-right,-down)
eventCaption.layer.shadowOffset = CGSizeMake(0.0f, 0.8f);
非常感謝!我甚至沒有想過要做一個陣列。我認爲有某種默認方法。再次感謝! –