iOS Question Gradient color with direction

Chris Guanzon

Active Member
Licensed User
Longtime User
Put an ImageView inside a panel or put an ImageView behind the button.

If you want to use the inline code to make the gradient then add these two lines:
B4X:
   gradient.startPoint = CGPoint(x: 0, y: 0);
    gradient.endPoint = CGPoint(x: 1, y: 1 );

I added these two lines
B4X:
   gradient.startPoint = CGPoint(x: 0, y: 0);
    gradient.endPoint = CGPoint(x: 1, y: 1 );

B4X:
#If OBJC
- (void)SetGradient: (UIView*) View :(UIColor*) Color1 :(UIColor*) Color2{
    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.startPoint = CGPoint(x: 0, y: 0);
    gradient.endPoint = CGPoint(x: 1, y: 1 );
    gradient.colors = [NSArray arrayWithObjects:(id)Color1.CGColor, (id)Color2.CGColor, nil];
    gradient.frame = View.bounds;
    [View.layer insertSublayer:gradient atIndex:0];
   
}
#end if

but got an error while compiling.

Error:

B4X:
Error: ** BUILD FAILED **


The following build commands failed:
    CompileC /Users/arthurgalenzoga/Downloads/B4iBuildServer/UploadedProjects/<user id>/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/arm64/b4i_main.o /Users/arthurgalenzoga/Downloads/B4iBuildServer/UploadedProjects/<user id>/B4iProject/b4i_main.m normal arm64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
 
Upvote 0

Chris Guanzon

Active Member
Licensed User
Longtime User
Correct code:
B4X:
gradient.startPoint = CGPointMake(0, 0);
gradient.endPoint = CGPointMake(1, 1);


thanks sir @Erel , here's the code I used:


B4X:
- (void)SetGradient: (UIView*) View :(UIColor*) Color1 :(UIColor*) Color2{
    CAGradientLayer *gradient = [CAGradientLayer layer];
    
    gradient.frame = View.bounds;   
    gradient.startPoint = CGPointZero;
    gradient.endPoint = CGPointMake(1, 1);
    gradient.colors = [NSArray arrayWithObjects:(id)Color1.CGColor, (id)Color2.CGColor, nil];
    
    [View.layer insertSublayer:gradient atIndex:0];
}
 
Upvote 0
Top