본문 바로가기
iOS/Objective-C

UIView에 그라데이션 적용하기

by 패쓰킴 2022. 4. 1.
728x90

 

 

- (void)viewDidLoad {
    [super viewDidLoad];

    CAGradientLayer * gradient = [CAGradientLayer new];
    gradient.colors = @[(id)[[UIColor yellowColor] colorWithAlphaComponent:0.6].CGColor,(id)[UIColor redColor].CGColor, (id)[UIColor blueColor].CGColor];
    gradient.locations = @[@0.0f, @0.5f];
    [_gradientView setBackgroundColor:[UIColor clearColor]];
    CALayer * backgroundLayer = gradient;
    backgroundLayer.frame = CGRectMake(_gradientView.bounds.origin.x, _gradientView.bounds.origin.y, self.view.frame.size.width, 240);
    [_gradientView.layer insertSublayer:backgroundLayer atIndex:0];
}

 

 

참고 :

https://stackoverflow.com/questions/24380535/how-to-apply-gradient-to-background-view-of-ios-swift-app

https://es1015.tistory.com/411

728x90

'iOS > Objective-C' 카테고리의 다른 글

integer 값 참조 오류  (0) 2022.05.20
Extension  (0) 2022.04.25
스트링 인터닝(String Interning)  (0) 2021.12.15
cornerRadius 원하는 부분에만 적용  (0) 2021.12.15
Push Notification  (0) 2021.12.06

댓글