Hello
There is any issue with NSArray and WithObjects. I’m trying to set gradient for button. This code do not compile because first NSArray parameter should be id - compiler says. Casting it to id give error that it cannot be casted as id. Closed circle. In Objective-c all params for gradient are casted as id.
CAGradientLayer gradientLayer = CAGradientLayer.layer();
gradientLayer.frame = butt.layer.bounds;
gradientLayer.colors = new NSArray WithObjects(UIColor.blackColor.CGColor, UIColor.whiteColor.CGColor, null);
gradientLayer.locations = NSArray.arrayWithObjects(NSNumber.numberWithFloat(0), NSNumber.numberWithFloat(1), null);
gradientLayer.cornerRadius = butt.layer.cornerRadius;
butt.layer.addSublayer(gradientLayer);
This one works, but first parameter is ignored in gradient (must be CGColorRef):
gradientLayer.colors = new NSArray WithObjects(UIColor.blackColor, UIColor.whiteColor.CGColor, null);
How to resolve, what I’m doing wrong?
Original Objective-C code (colors are different). Please use oxidizer and try to compile:
gradientLayer.colors = [NSArray arrayWithObjects:
(id)[UIColor colorWithWhite:1.0f alpha:0.1f].CGColor,
(id)[UIColor colorWithWhite:0.4f alpha:0.5f].CGColor,
nil];
Aha, QuartzCore reference must be added.
[EDIT[
Temporary workaround is to define first object and location as UIColor (blank - which is bad as color value for gradient), second param will be first color and add location for second (really first) same as first.
gradientLayer.colors = new NSArray WithObjects(UIColor.blackColor, UIColor.blackColor.CGColor, UIColor.whiteColor.CGColor, null);
gradientLayer.locations = NSArray.arrayWithObjects(NSNumber.numberWithFloat(0), NSNumber.numberWithFloat(0), NSNumber.numberWithFloat(1), null);
b.r.